PHP documentation states:
Since PHP 5, new returns a reference automatically
Any examples to illustrate this statement?
PHP documentation states:
Since PHP 5, new returns a reference automatically
Any examples to illustrate this statement?
Here is an example:
class reftest
{
public $a = 1;
}
$reference = new reftest();
$reference2 = $reference;
$reference->a = 2;
echo $reference->a; // echoes 2.
echo $reference2->a; // echoes 2.
Note that both $reference and $reference2 have the value of the member $a equal to 2, despite the value was only assigned to the $reference.
<?php
$a = new ClassA();
$b = $a;
Variables $a and $b are pointing to the same place, where ClassA resource exists.