I have a question ...
The following code:
<?php
$instancia = new ClaseSencilla();
$asignada = $instancia;
$referencia =& $instancia;
$instancia->var = '$asignada tendrá este valor';
$instancia = null; // $instancia y $referencia son null
var_dump($instancia);
var_dump($referencia);
var_dump($asignada);
?>
Which produces the following output:
NULL
NULL
object(ClaseSencilla)#1 (1) {
["var"]=>
string(27) "$asignada tendrá este valor"
}
Line number 5: "string (27)" $ assigned ......... "
Why do you return that?
I ask because my logic (which is certainly wrong) says that I should return NULL or an error because at the time I was assigned the value of $instancia" a "$asignada
... $asignada
had no value in $var
, the value was assigned after! ( $instancia->var = $asignada
will have ....)
The example I did not try it out of the official documentation of php: link
I hope you understand my query and that you can get rid of my doubts!
Thank you!