Zend
200-550 · Question #82
Given the following code, what will the output be: trait MyTrait { private $abc = 1; public function increment() { $this->abc++; } public function getValue() { return $this->abc; } } class MyClass {…
The correct answer is D. int(3). See the full explanation below for the reasoning.
Question
Given the following code, what will the output be:
trait MyTrait { private $abc = 1; public function increment() { $this->abc++; } public function getValue() { return $this->abc; } } class MyClass { use MyTrait; public function incrementBy2() { $this->increment(); $this->abc++; } } $c = new MyClass; $c->incrementBy2(); var_dump($c->getValue());
Options
- AFatal error: Access to private variable MyTrait::$abc from context MyClass
- BNotice: Undefined property MyClass::$abc
- Cint(2)
- Dint(3)
- ENULL
How the community answered
(21 responses)- A5% (1)
- D86% (18)
- E10% (2)
Community Discussion
No community discussion yet for this question.