php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14626 calling a method "magically" turns the object into a reference to itself
Submitted: 2001-12-20 11:27 UTC Modified: 2002-06-01 09:55 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: ivan dot lamouret at novitek dot fr Assigned:
Status: Closed Package: Class/Object related
PHP Version: 4.1.0 OS: linux Suse
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ivan dot lamouret at novitek dot fr
New email:
PHP Version: OS:

 

 [2001-12-20 11:27 UTC] ivan dot lamouret at novitek dot fr
Calling an object's method turn the object into a reference to itself. When the object is itself an array's value (or an object's instance variable) this shows up when copying (with simple assignement) the surrounding array (or object).  

class bar{
 var $my_var = 'bar';
 function buggy(){/*nothing needed here*/}
}

$foo[0] = new bar();
$foo[0]->buggy(); // turns the array's value into a reference to the object

$new = $foo;
$new[0]->my_var = 'new';
echo $foo[0]->my_var;// echoes 'new' !!


Comment out the call to buggy(), or use var_dump before and after this call to see the magic transformation of $foo[0] from object(bar) to &object(bar).

Tested with 4.0.3 and 4.1.
The same bug has been reported under #11543 (open but unanswered). The code above is much simpler than that in the original bug report. (I could not edit that one :))

best regards

Ivan

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-06-01 09:55 UTC] mfischer@php.net
The expected behaviuor for ZE2 will be that $foo[0]->my_var == $new[0]->my_var == 'new'. The arrays are different but they contain one and the same object.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 02:01:28 2024 UTC