ID:               33207
 Updated by:       [EMAIL PROTECTED]
 Reported By:      phallstrom at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Arrays related
 Operating System: FreeBSD 4.9-RELEASE
 PHP Version:      4.3.11
 New Comment:

Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.




Previous Comments:
------------------------------------------------------------------------

[2005-05-31 23:53:16] phallstrom at gmail dot com

Description:
------------
I came across a very odd bug in 4.3.10 (and 4.3.11).  It's not in
4.3.4, and it's not in 5.0.4.

My understanding is that in 4.x objects are assigned by value.  So, why
in the first part of the code is the output of serialize() indicating a
reference?  This would suggest that objects are being copied by
reference.

But in the second when I change $ary[1]->name, the output of the
serialize only changes the second element, not both.  Also, changing
$obj->name doesn't have any effect on $ary[0] or $ary[1]. Which would
suggest that $ary[0] and $ary[1] are NOT the SAME thing.

The output below is from 4.3.11.  4.3.4 does not have this problem and
the serialize() output does not indicate any reference.

In 5.0.4, the everything works like I'd expect it to since objects are
assigned by reference.

It's almost like $obj is partially being copied by reference and that
serialize is picking up on that or something...

Reproduce code:
---------------
<?php

$obj->name = "Homer";
$ary[] = $obj;
$ary[] = $obj;

$obj1->name = "Homer";
$ary[] = $obj1;

print_r($ary);
print("\n");
print ( serialize($ary) );

print("\n\n---------------------------------------\n\n");

unset($obj); unset($obj1); unset($ary);

$obj->name = "Homer";
$ary[] = $obj;
$ary[] = $obj;

$obj1->name = "Homer";
$ary[] = $obj1;

$ary[1]->name = "Marge";

print_r($ary);
print("\n");
print ( serialize($ary) );

?>


Expected result:
----------------
I would expect to *not* see any indications of references (i.e. "r:2")
in the serialized output.

Actual result:
--------------
Array
(
    [0] => stdClass Object
        (
            [name] => Homer
        )

    [1] => stdClass Object
        (
            [name] => Homer
        )

    [2] => stdClass Object
        (
            [name] => Homer
        )

)

a:3:{i:0;O:8:"stdClass":1:{s:4:"name";s:5:"Homer";}i:1;r:2;i:2;O:8:"stdClass":1:{s:4:"
name";s:5:"Homer";}}

---------------------------------------

Array
(
    [0] => stdClass Object
        (
            [name] => Homer
        )

    [1] => stdClass Object
        (
            [name] => Marge
        )

    [2] => stdClass Object
        (
            [name] => Homer
        )

)

a:3:{i:0;O:8:"stdClass":1:{s:4:"name";s:5:"Homer";}i:1;O:8:"stdClass":1:{s:4:"name";s:
5:"Marge";}i:2;O:8:"stdClass":1:{s:4:"name";s:5:"Homer";}}



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33207&edit=1

Reply via email to