#32137 [NEW]: Objects are not being passed by reference

From: Date: Mon, 28 Feb 2005 19:39:29 +0000
Subject: #32137 [NEW]: Objects are not being passed by reference
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-74701@lists.php.net to get a copy of this message
From: tigr at mail15 dot com Operating system: Windows 98 PHP version: 5.0.3 PHP Bug Type: Zend Engine 2 problem Bug description: Objects are not being passed by reference Description: ------------ I make one object instance. Then, pass it to another object. Then, change original instance. Now I have two different objects. Reproduce code: --------------- <?php class classA { public $id = ""; public function __construct($id) { $this->id = $id; } } class classB { public $reference = null; public function __construct($ref) { $this->reference = $ref; } } $a = new classA("object 1"); $test = new classB($a); $a = new classA("object 2"); echo $a->id, "<br>", $test->reference->id; ?> Expected result: ---------------- object 2 object 2 Actual result: -------------- object 2 object 1 However, adding references solves the problem: class classB { public $reference = null; public function __construct(&$ref) { $this->reference =& $ref; } } This works as expected. So, the question is are objects being passed by reference or what? -- Edit bug report at http://bugs.php.net/?id=32137&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32137&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32137&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32137&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=32137&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=32137&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=32137&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=32137&r=needscript Try newer version: http://bugs.php.net/fix.php?id=32137&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=32137&r=support Expected behavior: http://bugs.php.net/fix.php?id=32137&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=32137&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=32137&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=32137&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32137&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=32137&r=dst IIS Stability: http://bugs.php.net/fix.php?id=32137&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=32137&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=32137&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=32137&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=32137&r=mysqlcfg

« previous php.bugs (#74701) next »