#32137 [Fbk->Opn]: Objects are not being passed by reference

From: Date: Tue, 01 Mar 2005 12:04:21 +0000
Subject: #32137 [Fbk->Opn]: Objects are not being passed by reference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-77258@lists.php.net to get a copy of this message
ID: 32137 User updated by: tigr at mail15 dot com Reported By: tigr at mail15 dot com -Status: Feedback +Status: Open Bug Type: Zend Engine 2 problem Operating System: Windows 98 PHP Version: 5.0.3 New Comment: Checked on these snaps, no changes. Well, maybe this is due to incorrect understanding of what object passing by reference means? Maybe this is a documentation problem? I've added detailed explanation here: http://www.php.net/manual/en/language.oop5.basic.php Previous Comments: ------------------------------------------------------------------------ [2005-02-28 20:42:40] sniper@php.net Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2005-02-28 20:39:29] tigr at mail15 dot com 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 this bug report at http://bugs.php.net/?id=32137&edit=1

« previous php.bugs (#77258) next »