Zend
200-710 · Question #36
What is the output of the following code? class C { public $x = 1; function __construct() { ++$this->x; } function __invoke() { return ++$this->x; } function __toString() { return (string)…
The correct answer is D. 3. See the full explanation below for the reasoning.
Magic Methods and Traits
Question
What is the output of the following code?
class C {
public $x = 1;
function __construct() { ++$this->x; }
function __invoke() { return ++$this->x; }
function __toString() { return (string) --$this->x; }
}
$obj = new C();
echo $obj();
Options
- A0
- B1
- C2
- D3
How the community answered
(26 responses)- A8% (2)
- B4% (1)
- C8% (2)
- D81% (21)
Topics
#__invoke#__construct#__toString#magic method order
Community Discussion
No community discussion yet for this question.