Zend Certified PHP Engineer (ZCE) PHP 5.5 — Question 1

Which line of code can be used to replace the INSERT comment in order to output "hello"? class C { public $ello = 'ello'; public $c; public $m; function __construct($y) {
$this->c = static function($f) {
// INSERT LINE OF CODE HERE
};
$this->m = function() {
return "h";
};
}
}
$x = new C("h");
$f = $x->c;
echo $f($x->m);

Answer options

Correct answer: B

Explanation

The correct answer is B because it correctly calls the function $f, which is assigned the static function returning the output of $x->m, and appends 'ello' to it. Option A is incorrect since it uses $this->m() which is not in the current scope. Option C does not utilize the function $f and instead directly concatenates 'h' with $this->ello. Option D attempts to use the variable $y, which is not defined in the context of the static function.