13. Consider the following script. What will it output?
<?php
$global_obj = null;
class my_class
{
var $value;
function my_class()
{
global $global_obj;
$global_obj = &$this;
}
}
$a = new my_class;
$a->my_value = 5;
$global_obj->my_value = 10;
echo $a->my_value;
?>
Вариант ответа 1 - A) 5
Вариант ответа 2 - B) 10
Вариант ответа 3 - C) Nothing
Вариант ответа 4 - D) The constructor will throw an error
Вариант ответа 5 - E) 510
Комментарий: 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.