PrepAway - Latest Free Exam Questions & Answers

What change must be made to the class for the code to work as written?

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

PrepAway - Latest Free Exam Questions & Answers

A.
Nothing, this code works just fine.

B.
Add __set method doing $this->v[$var] = $val

C.
Rewrite __get as: public function __get(&$v)

D.
Rewrite __get as: public function &__get($v)

E.
Make __get method static


Leave a Reply

Your email address will not be published. Required fields are marked *