200-550 practice questions, page 8 of 9, with answer review and explanations.
Question 36
Late static binding is used in PHP to:
Load dynamic libraries and extensions at runtime
Use caller class information provided in static method call
Resolve undefined class names by automatically including needed files
Find proper method to call according to the call arguments
Question 37
What is the output of the following code? class Test { public function __call($name, $args) { call_user_func_array(array('static', "test$name"), $args); } public function testS($l) { echo "$l,"; } } class Test2 extends Test { public function testS($l) { echo "$l,$l,"; } } $test = new Test2(); $test->S('A');
A,
A,A,
A,A,A,
PHP Warning: call_user_func_array() expects parameter 1 to be a valid callback
Question 38
Which of the following tasks can be achieved by using magic methods? (Choose 3)
Initializing or uninitializing object data
Creating a new stream wrapper
Creating an iterable object
Processing access to undefined methods or properties
Overloading operators like +, *, etc.
Converting objects to string representation
Question 39
How should class MyObject be defined for the following code to work properly? Assume $array is an array and MyObject is a user-defined class. $obj = new MyObject(); array_walk($array, $obj);
MyObject should extend class Closure
MyObject should implement interface Callable
MyObject should implement method __call
MyObject should implement method __invoke
Question 40
Consider the following code. What change must be made to the class for the code to work as written? class Magic { protected $v = array("a" => 1, "b" => 2, "c" => 3); public function __get($v) { return $this->v[$v]; } } $m = new Magic(); $m->d[] = 4; echo $m->d[0];