nerdexam
Zend

200-710 · Question #111

What is the output of the following code? ``php class Number { private static $sv = 10; private $v; public function __construct($v) { $this->v = $v; } public function mul() { return static function…

The correct answer is C. 50. See the full explanation below for the reasoning.

Closures

Question

What is the output of the following code?
class Number {
 private static $sv = 10;
 private $v;
 public function __construct($v) { $this->v = $v; }
 public function mul() {
 return static function ($x) {
 return isset($this->v) ? $this->v*$x : self::$sv*$x;
 };
 }
}
$one = new Number(1);
$two = new Number(2);
$double = $two->mul();
$x = Closure::bind($double, null, 'Number');
echo $x(5);

Options

  • A5
  • B10
  • C50
  • DFatal error

How the community answered

(23 responses)
  • A
    4% (1)
  • B
    4% (1)
  • C
    83% (19)
  • D
    9% (2)

Topics

#static closures#Closure::bind#static scope#null binding

Community Discussion

No community discussion yet for this question.

Full 200-710 Practice