PHP Test online


2. At the end of the execution of the following script, which values will be stored in the $a->my_value array?

<?php
class my_class
{
var $my_value = array();
function my_class ($value)
{
$this->my_value[] = $value;
}
function set_value ($value)
{
$this->$my_value= $value;
}
}
$a = new my_class ( a );
$a->my_value[] = b ;
$a->set_value ( c );
$a->my_class( d );
?>


Вариант ответа 1 - A) c

Вариант ответа 2 - B) b

Вариант ответа 3 - C) a

Вариант ответа 4 - D) d

Вариант ответа 5 - E) e


Comments: The three correct answers are B, C and D. The set_value method of my_class will not work correctly because it uses the expression $this->$my_value, which is a “variable variable” that, under the circumstances will never correspond to any real property of the class.

Comments

User nameComment
User name
Comment text
Code