#33586 [Com]: Serialization breaks references
| From: | jfranklin at gmail dot com | Date: | Mon, 07 Nov 2005 01:27:50 +0000 |
| Subject: | #33586 [Com]: Serialization breaks references | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-87734@lists.php.net to get a copy of this message | ||
ID: 33586
Comment by: jfranklin at gmail dot com
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 apologize for "cluttering the database" as you say, but this would be
a super bug to put some time into and get fixed.
Previous Comments:
------------------------------------------------------------------------
[2005-10-07 04:36:42] james at gogo dot co dot nz
This has always been a problem, at least in 4.x (I presume it still is
the same), I wrote an article about it a couple of years back now.
http://code.gogo.co.nz/dev-2-dev/serialize-unserialize.html
The workaround that worked at the time at least is to force passing in
a reference:
$serializedFoo = serialize(&$myFoo);
------------------------------------------------------------------------
[2005-09-02 18:28:07] sr at brightlight dot ch
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
------------------------------------------------------------------------
[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
------------------------------------------------------------------------
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/33586
--
Edit this bug report at http://bugs.php.net/?id=33586&edit=1