Zend
200-550 · Question #31
Consider the following code. What change must be made to the class for the code to work as written? class Magic { protected $v = array("a" => 1, "b" => 2, "c" => 3); public function __get($v) {…
The correct answer is D. Rewrite __get as: public function &__get($v). See the full explanation below for the reasoning.
Question
Consider the following code. What change must be made to the class for the code to work as written? class Magic { protected $v = array("a" => 1, "b" => 2, "c" => 3); public function __get($v) { return $this->v[$v]; } } $m = new Magic(); $m->d[] = 4; echo $m->d[0];
Options
- ANothing, this code works just fine.
- BAdd __set method doing $this->v[$var] = $val
- CRewrite __get as: public function __get(&$v)
- DRewrite __get as: public function &__get($v)
- EMake __get method static
How the community answered
(28 responses)- A11% (3)
- C4% (1)
- D82% (23)
- E4% (1)
Community Discussion
No community discussion yet for this question.