|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-02-28 20:42 UTC] sniper@php.net
[2005-03-01 13:04 UTC] tigr at mail15 dot com
[2005-03-01 14:48 UTC] ericvanblokland at gmail dot com
[2005-04-27 15:54 UTC] vrana@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 20:00:02 2025 UTC |
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?