|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24485 $a = $b; become $a=&$b; when I use a function (PHP 4 only!)
Submitted: 2003-07-03 10:17 UTC Modified: 2008-07-11 21:02 UTC
Avg. Score:3.9 ± 1.3
Reproduced:16 of 16 (100.0%)
Same Version:1 (6.2%)
Same OS:6 (37.5%)
From: bugs dot php dot net at public dot salagir dot com Assigned:
Status: Wont fix Package: Scripting Engine problem
PHP Version: 4CVS-2005-08-23 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
40 + 33 = ?
Subscribe to this entry?

 [2003-07-03 10:17 UTC] bugs dot php dot net at public dot salagir dot com
In an array, classes become classes references when I use a function member.

Because of that, I don't copy it anymore, I just produce more  pointers to it.
(see the '&' in the var dump)

If you comment the magic line, the bug won't appear.

Tested under linux (php 4.1.2 and 4.2.3)
and windows (php 4.3.2)

Reproduce code:
class AAAAA  {
    var $value;
    function AAAAA() {}
    function show() { return 5; }
$A = array(new AAAAA());
    $A[0]->show(); /* magic line */
$A[0]->value = 'A';
$B = $A;
$B[0]->value = 'B';
echo $A[0]->value.$B[0]->value;
echo "\n";
var_dump( $A );


Expected result:
array(1) {
  object(aaaaa)(1) {
    string(1) "A"

Actual result:
array(1) {
  &object(aaaaa)(1) {
    string(1) "B"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-17 14:03 UTC]
The following piece produces a similar result:

class foo {}
$a = array(new foo());
function show(&$this) { return 5; }

 [2005-01-21 00:19 UTC]
Still exists in 4.3, but has been already fixed in both 5.x branches.
 [2005-02-03 21:59 UTC]
This should NOT be a problem in PHP - but it is one in PHP 4. I've seen this too and have a patch almost ready that backports the fixes done in PHP 5.
 [2005-03-24 21:48 UTC]
For Derick, see also bug #32261 (same issue?)

 [2006-05-10 15:45 UTC] php dot net at nanonanonano dot net
CVS snapshot of PHP4 branch as of 2006-05-10 still shows this bug.

And to reiterate a previously mentioned very polite note to the php developers... please actually run the trivially simple test case given in the bug report to see if it has been fixed. Also, please reference a specific CVS commit (ok, harder to do with cvs than svn, but still possible) that you think fixes this bug. That way, we have a fighting chance of seeing where you are looking in the code and might be able to help out; at present, we don't know where to start.

(this is at least the fourth iteration of "try CVS"/"still broken" on this bug... it really is starting to make you look silly)
 [2006-05-20 11:01 UTC] antonio dot caprio at gmail dot com
To copy an array having object elements use unserialize(serialize(myarray)):

class test {
	VAR $test_var = 'this is default value';
$a = array(new test());
$b = $a;
$b[0]->test_var = 'this is set by $b instance';
$c = unserialize(serialize($a));
$c[0]->test_var = 'this is set by $c instance';
echo "---------------------\n";
Be careful! If you have __sleep AND __wakeup functions in your class you could have problem!
 [2006-07-19 14:06 UTC]
Derick: fixed, not fixed..?
 [2006-07-19 14:29 UTC]
I've no idea what this is about. It is apparently not related to the reference fixes we did for PHP 4.4 although at that time I thought it was.
 [2008-07-11 21:02 UTC]
We are sorry, but we can not support PHP 4 related problems anymore.
Momentum is gathering for PHP 6, and we think supporting PHP 4 will
lead to a waste of resources which we want to put into getting PHP 6

PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Sat Aug 13 20:05:45 2022 UTC