nerdexam
Zend

200-550 · Question #85

What is the output of the following code? class A { public $a = 1; public function __construct($a) { $this->a = $a; } public function mul() { return function($x) { return $this->a$x; }; } } $a = new…

The correct answer is B. 6. See the full explanation below for the reasoning.

Question

What is the output of the following code? class A { public $a = 1; public function __construct($a) { $this->a = $a; } public function mul() { return function($x) { return $this->a*$x; }; } } $a = new A(2); $a->mul = function($x) { return $x*$x; }; $m = $a->mul(); echo $m(3);

Options

  • A9
  • B6
  • C0
  • D3

How the community answered

(41 responses)
  • A
    10% (4)
  • B
    71% (29)
  • C
    5% (2)
  • D
    15% (6)

Community Discussion

No community discussion yet for this question.

Full 200-550 Practice