#36475 [Opn->Bgs]: Call by reference fails for objects

From: Date: Tue, 21 Feb 2006 12:50:33 +0000
Subject: #36475 [Opn->Bgs]: Call by reference fails for objects
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-93474@lists.php.net to get a copy of this message
ID: 36475 Updated by: mike@php.net Reported By: elmar dot hinz at team-red dot net -Status: Open +Status: Bogus Bug Type: Class/Object related Operating System: Linux/Debian PHP Version: 5.1.2 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#93474) next »