Bug #52521 [Fbk->Opn]: self-referenced array is copied instead of referenced after serialization

From: Date: Thu, 05 Aug 2010 14:18:58 +0000
Subject: Bug #52521 [Fbk->Opn]: self-referenced array is copied instead of referenced after serialization
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-153119@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52521&edit=1

 ID:                 52521
 User updated by:    martin dot leucht at gmail dot com
 Reported by:        martin dot leucht at gmail dot com
-Summary:            serialize() loses reference to root
+Summary:            self-referenced array is copied instead of
                     referenced after serialization
-Status:             Feedback
+Status:             Open
 Type:               Bug
-Package:            *Programming Data Structures
+Package:            Arrays related
 Operating System:   WIN32
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

// updated bug information


Previous Comments:
------------------------------------------------------------------------
[2010-08-04 22:50:22] martin dot leucht at googlemail dot com

It seems it is array-related. The same thing using the stdclass works
fine.

Test script:
------------
<?php

$Object = (object)array(
	'a' => 1,
	'b' => &$Object,
);
print_r($Object);

$Array = array(
	'a' => 1,
	'b' => &$Array,
);
print_r($Array);

$Array = unserialize(serialize($Array));
$Object = unserialize(serialize($Object));

$Object->b->a = 2;
print_r($Object);

$Array['b']['a'] = 2;
print_r($Array);

?>

Actual result:
--------------
stdClass Object
(
    [a] => 1
    [b] => stdClass Object
 *RECURSION*
)
Array
(
    [a] => 1
    [b] => Array
        (
            [a] => 1
            [b] => Array
 *RECURSION*
        )

)
stdClass Object
(
    [a] => 2
    [b] => stdClass Object
 *RECURSION*
)
Array
(
    [a] => 1
    [b] => Array
        (
            [a] => 2
            [b] => Array
 *RECURSION*
        )

)

------------------------------------------------------------------------
[2010-08-04 22:03:08] martin dot leucht at googlemail dot com

Okay, I finally made it though. I setup a build environment, built the
latest dev-version of PHP and ran the test script. But still: identical
results.

Please tell me how can I provide some help or assistence to solve this
issue?!

------------------------------------------------------------------------
[2010-08-03 13:23:39] martin dot leucht at gmail dot com

Sorry, but there are no builds on the Windows snapshots page and as I do
not maintain a PHP build environment (nor am currently willing to do so
due to a lack of time) I can not test it right now.
Could you please give me a hint when the snapshot builds are available
or if anyone else can do this test using the given test script above.

------------------------------------------------------------------------
[2010-08-03 09:53:39] mike@php.net

Please try using this snapshot:

  http://snaps.php.net/php-trunk-latest.tar.gz
 
For Windows:

  http://windows.php.net/snapshots/

Could you please try a trunk snapshot, IIRC this problem might be fixed
already.

Thanks.

------------------------------------------------------------------------
[2010-08-03 09:27:20] martin dot leucht at gmail dot com

I have to correct myself:

> If I unserialize the "correct" serialized string, it works correctly.
It just works for print_r() afterwards, but if I do some stuff on the
referenced value it creates even more confusing structures.

Test script:
------------
echo "*** using correct value ***\n\n";

$Array = unserialize('a:2:{s:1:"a";i:1;s:1:"b";R:1;}');
echo "print_r():\n";
echo "----------\n";
print_r($Array);
echo "\n";

$Array['b']['a'] = 2;
echo "print_r():\n";
echo "----------\n";
print_r($Array);
echo "\n";

Actual result
-------------
*** using correct value ***

print_r():
----------
Array
(
    [a] => 1
    [b] => Array
 *RECURSION*
)

print_r():
----------
Array
(
    [a] => 1
    [b] => Array
        (
            [a] => 2
            [b] => Array
                (
                    [a] => 1
                    [b] => Array
 *RECURSION*
                )

        )

)

Expected result
---------------
*** using correct value ***

print_r():
----------
Array
(
    [a] => 1
    [b] => Array
 *RECURSION*
)

print_r():
----------
Array
(
    [a] => 2
    [b] => Array
 *RECURSION*
)

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


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=52521


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


Thread (8 messages)

« previous php.bugs (#153119) next »