#39202 [Bgs->Opn]: Temporary tables with references dereference

From: Date: Fri, 20 Oct 2006 16:07:17 +0000
Subject: #39202 [Bgs->Opn]: Temporary tables with references dereference
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-103804@lists.php.net to get a copy of this message
ID: 39202 User updated by: cpriest at warpmail dot net Reported By: cpriest at warpmail dot net -Status: Bogus +Status: Open Bug Type: Arrays related Operating System: Apache 2.0.55 PHP Version: 5.1.6 New Comment: I think there's some confusion here, if you look at the code source I am only creating two objects. When I call getReferenced() it returns a table which has references to the created objects. When I go to change the name of the object in the second table (the one with references) it doesn't change the real object. For some reason there are then three objects when only two have been created. If this is the expected behavior can you explain why? I don't understand why a third object is being created when I have used references. Previous Comments: ------------------------------------------------------------------------ [2006-10-20 08:42:56] tony2001@php.net See my explanation in the previous message. No bug here. ------------------------------------------------------------------------ [2006-10-20 00:18:12] cpriest at warpmail dot net Expected: ------------------------------------------ Array ( [Test] => myClassA Object ( [Name] => Object 3 ) [Test2] => myClassA Object ( [Name] => Object 2 ) ) Array ( [Test] => myClassA Object ( [Name] => Object 3 ) [Test2] => myClassA Object ( [Name] => Object 2 ) ) Actual: -------------------------------------------- Array ( [Test] => myClassA Object ( [Name] => Object 1 ) [Test2] => myClassA Object ( [Name] => Object 2 ) ) Array ( [Test] => myClassA Object ( [Name] => Object 3 ) [Test2] => myClassA Object ( [Name] => Object 2 ) ) ------------------------------------------------------------------------ [2006-10-19 21:11:57] tony2001@php.net Can't reproduce. After the first print_r() I see "Object 1" (because the object haven't been changed yet), after ther second call I get "Object 3", which is expected too. Hint: when we say "expected and actual results" we usually mean "copy/paste what you see and also attach what you expected to see", not a "I expect to see ..". ------------------------------------------------------------------------ [2006-10-19 20:56:01] cpriest at warpmail dot net Description: ------------ References in temporary tables de-reference their references upon crossing function boundaries Reproduce code: --------------- <?php class myClassA { public $Name = ''; function __construct($Name) { $this->Name = $Name; } } global $tblData; $tblData = array( 'Test' => new myClassA('Object 1'), 'Test2' => new myClassA('Object 2'), ); function getReferenced() { global $tblData; $tblData2 = array( 'Test' => &$tblData['Test'], 'Test2' => &$tblData['Test2'], ); return $tblData2; } echo '<plaintext>'; print_r($tblData); $tblData2 = getReferenced(); $tblData2['Test']->Name = 'Object 3'; print_r($tblData2); ?> Expected result: ---------------- I expect there to be only two objects at the end of the call, one with a Name of 'Object 3' and one with a Name of 'Object 2' Actual result: -------------- Three objects exist, 'Object 1', 'Object 2', and 'Object 3' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39202&edit=1

« previous php.bugs (#103804) next »