PHP Test online
13. Consider the following script. What will it output?Вариант ответа 1 - A) 5 Вариант ответа 2 - B) 10 Вариант ответа 3 - C) Nothing Вариант ответа 4 - D) The constructor will throw an error Вариант ответа 5 - E) 510 Comments: This is a really tricky one. Upon first examination, it would seem that the constructor of my_class stores a reference to itself inside the $global_obj variable. Therefore, one would expect that, when we later change the value of $global_obj->my_value to 10, the corresponding value in $a would change as well. Unfortunately, the new operator does not return a reference, but a copy of the newly created object. Therefore, the script will output 5 and the correct answer is A. |
Comments
| User name | Comment |
|---|
Русский