nerdexam
Zend

200-550 · Question #30

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.

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

(55 responses)
  • A
    13% (7)
  • B
    2% (1)
  • C
    5% (3)
  • D
    80% (44)

Community Discussion

No community discussion yet for this question.

Full 200-550 Practice