// test.php <?php class test{ private $variable = 'default'; public function &getVariable1(){ return $this -> variable; } public function getVariable2(){ $ref = &$this -> variable; return $ref; } public function &getVariable3(){ $ref = &$this -> variable; return $ref; } public function __destruct() { } } ?>
<?php include('class/test.php'); $test = new test(); $variable = $test -> getVariable1(); $variable = 'new value'; $variable = $test -> getVariable2(); $variable = 'new value'; $variable = $test -> getVariable3(); $variable = 'new value'; ?>
Czy potrafi mi ktoś wytłumaczyć dlaczego żadna z tych funkcji nie zwraca referencji? Da się takie coś wogóle zrobić?