ID: 27336
User updated by: hawcue at yahoo dot com
Reported By: hawcue at yahoo dot com
Status: Wont fix
Bug Type: Class/Object related
Operating System: Windows XP
PHP Version: 4.3.4
New Comment:
I believe this is a bug. It is related with
how PHP determines recursion levels. From
what we have observed, I think PHP determines
the recursion level by comparing the physical
addresses of two references. This is why
serialize(&$parentNode) works as expected
because the address is passed in.
Previous Comments:
------------------------------------------------------------------------
[2004-02-21 03:12:20] [EMAIL PROTECTED]
Don't mess with references and serializing. That doesn't work and it
won't work.
------------------------------------------------------------------------
[2004-02-20 16:22:53] hawcue at yahoo dot com
Description:
------------
Please read the codes first.
The actual output shows two copies of $parentNode are
generated by unserialize(). However, this is not
what I expect because I am using reference and
$newParent->child->parent and $newParent should
refer to the same storage if serialize/unserialize
works correctly.
The problem can be partially solved by using
the following line to do serialize:
$str = serialize(&$parentNode); // an ampersand is used
This will generate a compiling warning (depreciation
of using ampersand in function parameters).
Reproduce code:
---------------
class Node {
var $value;
var $child;
var $parent;
function Node($value) {
$this->value = $value;
}
function setParent(&$parent) {
$this->parent = &$parent;
}
function setChild(&$child) {
$this->child = &$child;
}
}
$parentNode = new Node('parent');
$childNode = new Node('child');
$parentNode->setChild($childNode);
$childNode->setParent($parentNode);
$str = serialize($parentNode);
$newParent = unserialize($str);
$newParent->value = 'new parent';
echo $newParent->child->parent->value;
echo $newParent->value;
Expected result:
----------------
new parent
new parent
Actual result:
--------------
parent
new parent
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=27336&edit=1