Zend
200-710 · Question #43
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);
The correct answer is D. MyObject should implement method __invoke. See the full explanation below for the reasoning.
Magic Methods and Traits
Question
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);
Options
- AMyObject should extend class Closure
- BMyObject should implement interface Callable
- CMyObject should implement method __call
- DMyObject should implement method __invoke
How the community answered
(28 responses)- A14% (4)
- B4% (1)
- C7% (2)
- D75% (21)
Topics
#__invoke#callable#array_walk#magic methods
Community Discussion
No community discussion yet for this question.