ID: 36475 Updated by: [EMAIL PROTECTED] Reported By: elmar dot hinz at team-red dot net -Status: Closed +Status: Bogus Bug Type: Class/Object related Operating System: Linux/Debian PHP Version: 5.1.2 New Comment:
Not a bug -> Bogus. Previous Comments: ------------------------------------------------------------------------ [2006-02-21 18:10:57] elmar dot hinz at team-red dot net It is not the behaviour what I would expect, but indeed no bug. So what happens in detail? Short analysis of the 2 steps: 1.) On function call $ref get's an alias to the outside variable $callback. 2.) Before any alterations on this double named variable happen, $ref is made an alias to a second variable $object (and gives up the fist variable in the same moment). Result: $callback and $object are not aliased to each other this way. ------------------------------------------------------------------------ [2006-02-21 13:50:32] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Think again about your code. ------------------------------------------------------------------------ [2006-02-21 13:12:14] elmar dot hinz at team-red dot net Description: ------------ Cannot access original objects by call by reference. function tryCallback(&$ref){ $ref =& $this->object; } Only a copies work: function tryCallback(&$ref){ $ref = $this->object; } Reproduce code: --------------- <?php class myObject{ var $value = 'The original value'; } function tryCallback(&$ref){ global $object; $ref =& $object; // in a class it would be: $ref =& $this->object; dump($ref, 'Before the proplem: The object is still here but will fail from outside.'); } function dump($var, $name){ print '<p style="background:#eeeeee;">' . $name . '</p>'; if($var){ print '<pre style="color:green">'; print_r($var); print '</pre>'; } else{ print '<p style="color:red"><strong>$var is empty!!!</strong></p>'; } } $object = new myObject(); tryCallback($callback); dump($callback, 'Here the object is missing in my test.'); $callback->value = 'Try to set a value.'; dump($callback, 'Ooops, what a funny object now.'); dump($object, 'This is the original object. Unaltered. No reference was created.'); ?> Expected result: ---------------- Dump 1: myObject Object ( [value] => The original value ) Dump 2: myObject Object ( [value] => The original value ) [...] Actual result: -------------- Dump 1: myObject Object ( [value] => The original value ) Dump 2: $var is empty!!! [...] ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=36475&edit=1