php.net |  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
Votes:20
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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bugs dot php dot net at public dot salagir dot com
New email:
PHP Version: OS:

 

 [2003-07-03 10:17 UTC] bugs dot php dot net at public dot salagir dot com
Description:
------------
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:
---------------
<?php
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:
----------------
AB
array(1) {
  [0]=>
  object(aaaaa)(1) {
    ["value"]=>
    string(1) "A"
  }
}

Actual result:
--------------
BB
array(1) {
  [0]=>
  &object(aaaaa)(1) {
    ["value"]=>
    string(1) "B"
  }
}


Patches

Pull Requests

History

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

<?php
class foo {}
$a = array(new foo());
function show(&$this) { return 5; }
show($a[0]);
var_dump($a);
?>

 [2005-01-21 00:19 UTC] tony2001@php.net
Still exists in 4.3, but has been already fixed in both 5.x branches.
 [2005-02-03 21:59 UTC] derick@php.net
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] sniper@php.net
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)):

<?php
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';
print_r($a);
print_r($b);
$c = unserialize(serialize($a));
$c[0]->test_var = 'this is set by $c instance';
echo "---------------------\n";
print_r($a);
print_r($b);
print_r($c);
?>
Be careful! If you have __sleep AND __wakeup functions in your class you could have problem!
 [2006-07-19 14:06 UTC] sniper@php.net
Derick: fixed, not fixed..?
 [2006-07-19 14:29 UTC] derick@php.net
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] jani@php.net
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
ready.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 19:01:31 2024 UTC