|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-02-21 13:50 UTC] mike@php.net
[2006-02-21 18:10 UTC] elmar dot hinz at team-red dot net
[2006-02-21 23:21 UTC] mike@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 18:00:01 2025 UTC |
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!!! [...]