#36475 [NEW]: Call by reference fails for objects

From: Date: Tue, 21 Feb 2006 12:12:15 +0000
Subject: #36475 [NEW]: Call by reference fails for objects
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-93472@lists.php.net to get a copy of this message
From: elmar dot hinz at team-red dot net Operating system: Linux/Debian PHP version: 5.1.2 PHP Bug Type: Class/Object related Bug description: Call by reference fails for objects 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 bug report at http://bugs.php.net/?id=36475&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=36475&r=trysnapshot44 Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=36475&r=trysnapshot51 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=36475&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=36475&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=36475&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=36475&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=36475&r=needscript Try newer version: http://bugs.php.net/fix.php?id=36475&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=36475&r=support Expected behavior: http://bugs.php.net/fix.php?id=36475&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=36475&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=36475&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=36475&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36475&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=36475&r=dst IIS Stability: http://bugs.php.net/fix.php?id=36475&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=36475&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=36475&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=36475&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=36475&r=mysqlcfg

« previous php.bugs (#93472) next »