Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Zend Exam 200-710 Topic 6 Question 92 Discussion

Actual exam question for Zend's 200-710 exam
Question #: 92
Topic #: 6
[All 200-710 Questions]

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];

Show Suggested Answer Hide Answer
Suggested Answer: D

Contribute your Thoughts:

Sharen
1 days ago
Ha! This is a classic trick question. The answer is clearly A, the code works just fine as is. Those other options are just trying to confuse us.
upvoted 0 times
...
Lili
3 days ago
I disagree, I believe the answer is D) Rewrite __get as: public function &__get($v)
upvoted 0 times
...
Tamekia
5 days ago
Hmm, I'm not so sure. I'm leaning towards D, where we need to use a reference in the __get method to allow modifying the array element.
upvoted 0 times
...
Corrie
7 days ago
I think the answer is B) Add __set method doing $this->v[$var] = $val
upvoted 0 times
...
Desire
7 days ago
Wow, this is a tricky one! I think the answer is B, since we need to add an __set method to allow writing to the array.
upvoted 0 times
Rima
57 minutes ago
I agree, adding an __set method would allow writing to the array.
upvoted 0 times
...
Crissy
2 days ago
I think the answer is B, we need to add an __set method.
upvoted 0 times
...
...

Save Cancel