Why the following
class AClass
{
public function __construct ()
{
$this->prop = \"Hello\";
}
public function &get ()
{
Consider this piece of code (It's the same as your code, just without everything else):
$value = new stdClass;
$ref = &$value;
$var = "Hello";
$ref = &$var; // this is where you write $ref = &$ref->get();
var_dump($value);
This gives as expected an empty object and not string(5) Hello
.
We're in line 4 overwriting the reference to $value
with a reference to $var
.
$ref
now holds a reference to $var
; the value of $value
remains unaffected.
$var
to $value
.$value
a reference to $var
.Assigning references to a variable via another referencing variable is just not possible in PHP.