ID: 33586
Comment by: sr at brightlight dot ch
Reported By: wmeler at wp dot pl
Status: Assigned
Bug Type: Scripting Engine problem
Operating System: *
PHP Version: 5CVS-2005-07-06
Assigned To: dmitry
New Comment:
I experienced a similar problem. An even simpler setup
already breaks unserialisation (php 5.0.4):
$rec = array('rec' => 'x');
$rec['rec'] = &$rec;
echo "print_r:\n".print_r($rec, true);
echo "\nafter unserialisation:\n".print_r(unserialize
(serialize($rec)), true);
The output will be:
print_r:
Array
(
[rec] => Array
*RECURSION*
)
after unserialisation:
Array
(
[rec] => Array
(
[rec] =>
)
)
With a few more dimensions before the recursion php will
even crash on OS X 10.4.1
regards
Previous Comments:
------------------------------------------------------------------------
[2005-07-22 08:52:12] wmeler at wp dot pl
Do you want simplest to debug example or complicated real world
example?
How about this :
<?
$c = array();
$d = array();
$c['d2']=&$d;
$d['c2']=&$c;
$x=unserialize(serialize($c));
$x['x']='x';
$c['x']='x';
var_dump($c);
var_dump($x);
?>
outputs remain the same
you can even substitute 'c' with 'parent' and 'd' with
'child' which
makes it more real but this would change outputs
------------------------------------------------------------------------
[2005-07-22 01:03:09] sniper@php.net
In your example you're making a reference to a non-existing variable.
Please come up with something more realistic.
------------------------------------------------------------------------
[2005-07-06 12:51:21] wmeler at wp dot pl
I've tried - nothing changed
------------------------------------------------------------------------
[2005-07-06 12:17:00] tony2001@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
------------------------------------------------------------------------
[2005-07-06 12:03:59] wmeler at wp dot pl
Description:
------------
After serializing variable with circular reference you get 2 copies of
root variable.
Look at output of reproduce code - var_dump outputs should be the same
but they are not.
for code:
$c['d2']=&$d;
$d['c2']=&$c;
echo serialize($c);
you get
a:1:{s:2:"d2";a:1:{s:2:"c2";a:1:{s:2:"d2";R:2;}}}
I think that it should be something like
a:1:{s:2:"d2";a:1:{s:2:"c2";R:1;}}
Reproduce code:
---------------
<?
$c['d2']=&$d;
$d['c2']=&$c;
$x=unserialize(serialize($c));
$x['x']='x';
$c['x']='x';
var_dump($c);
var_dump($x);
Expected result:
----------------
array(2) {
["d2"]=>
&array(1) {
["c2"]=>
&array(2) {
["d2"]=>
&array(1) {
["c2"]=>
&array(2) {
["d2"]=>
*RECURSION*
["x"]=>
string(1) "x"
}
}
["x"]=>
string(1) "x"
}
}
["x"]=>
string(1) "x"
}
array(2) {
["d2"]=>
&array(1) {
["c2"]=>
&array(2) {
["d2"]=>
&array(1) {
["c2"]=>
&array(2) {
["d2"]=>
*RECURSION*
["x"]=>
string(1) "x"
}
}
["x"]=>
string(1) "x"
}
}
["x"]=>
string(1) "x"
}
Actual result:
--------------
array(2) {
["d2"]=>
&array(1) {
["c2"]=>
&array(2) {
["d2"]=>
&array(1) {
["c2"]=>
&array(2) {
["d2"]=>
*RECURSION*
["x"]=>
string(1) "x"
}
}
["x"]=>
string(1) "x"
}
}
["x"]=>
string(1) "x"
}
array(2) {
["d2"]=>
&array(1) {
["c2"]=>
array(1) {
["d2"]=>
&array(1) {
["c2"]=>
array(1) {
["d2"]=>
*RECURSION*
}
}
}
}
["x"]=>
string(1) "x"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=33586&edit=1