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 200-710 Exam - 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:

0/2000 characters
Dorcas
3 months ago
I thought it worked fine as is, but I guess not!
upvoted 0 times
...
Jame
3 months ago
Wait, why would you need a __set? Isn't it just a getter?
upvoted 0 times
...
Nickolas
3 months ago
Totally agree, option B is the way to go!
upvoted 0 times
...
Jeannetta
4 months ago
You need to add a __set method for that to work.
upvoted 0 times
...
Kris
4 months ago
Making __get static? That's a no-go.
upvoted 0 times
...
Filiberto
4 months ago
I’m confused about the static part in option E. I don’t recall that being necessary for this kind of situation.
upvoted 0 times
...
Nelida
4 months ago
This question feels familiar. I think we might have done a similar one where we had to implement __set for dynamic properties.
upvoted 0 times
...
Julio
5 months ago
I'm not entirely sure, but I remember something about needing to rewrite __get to return a reference. Maybe option D?
upvoted 0 times
...
Virgilio
5 months ago
I think we need to add a __set method to handle the assignment to $m->d. That seems to make sense based on what we practiced.
upvoted 0 times
...
Cathrine
5 months ago
I'm not sure about this one. I'll need to review the PHP magic methods and how they work with arrays before I can decide on the best approach.
upvoted 0 times
...
Brinda
5 months ago
I'm pretty confident that the answer is B. We need to add an __set method to the class to allow for setting new properties.
upvoted 0 times
...
Reed
5 months ago
Okay, I think I've got it. The issue is that we're trying to access a property that doesn't exist in the $v array, so we need to add a way to handle that.
upvoted 0 times
...
Joseph
6 months ago
Hmm, I'm a bit confused by the question. I'm not sure what change needs to be made to the class for the code to work as written.
upvoted 0 times
...
Hester
6 months ago
This looks like a tricky one. I'll need to carefully read through the code and think about how the __get method works.
upvoted 0 times
...
Lili
8 months ago
I see your point, Mari. Maybe we are overthinking it.
upvoted 0 times
...
Mari
8 months ago
I think the correct answer is A) Nothing, this code works just fine.
upvoted 0 times
...
Sherell
8 months ago
Wait, this isn't a magic trick question? Darn, and here I was hoping to pull a rabbit out of my hat. Oh well, I'll just go with option B and see if I can make a few galleons appear instead.
upvoted 0 times
Dierdre
6 months ago
I'm curious to see if this change will work. Good luck!
upvoted 0 times
...
Denae
6 months ago
That's a good choice. Let's see if you can make those galleons appear!
upvoted 0 times
...
Ruth
6 months ago
Yeah, adding the __set method should do the trick.
upvoted 0 times
...
Felix
7 months ago
Option B) Add __set method doing $this->v[$var] = $val
upvoted 0 times
...
Vinnie
7 months ago
I think option B is the way to go.
upvoted 0 times
...
...
Corrie
8 months ago
But wouldn't adding a reference in __get cause potential issues?
upvoted 0 times
...
Margarita
8 months ago
This question is making my brain hurt. I'm just going to go with the option that sounds the most complicated - let's go with E and make __get static. That'll show 'em!
upvoted 0 times
...
Denise
8 months ago
I'm feeling a bit lost here. Maybe I should've paid more attention in my PHP classes... Anyway, I'll go with C and hope for the best!
upvoted 0 times
Kaycee
8 months ago
B) Add __set method doing $this->v[$var] = $val
upvoted 0 times
...
Brittney
8 months ago
C) Rewrite __get as: public function __get(&$v)
upvoted 0 times
...
...
Sharen
8 months 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
8 months ago
I disagree, I believe the answer is D) Rewrite __get as: public function &__get($v)
upvoted 0 times
...
Tamekia
8 months 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
Tijuana
8 months ago
User 2: Yeah, that makes sense. It would allow modifying the array element.
upvoted 0 times
...
Desmond
8 months ago
User 1: I think D is the correct option, we need to use a reference in the __get method.
upvoted 0 times
...
...
Corrie
9 months ago
I think the answer is B) Add __set method doing $this->v[$var] = $val
upvoted 0 times
...
Desire
9 months 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
8 months ago
I agree, adding an __set method would allow writing to the array.
upvoted 0 times
...
Crissy
8 months ago
I think the answer is B, we need to add an __set method.
upvoted 0 times
...
...

Save Cancel