From:             hawcue at yahoo dot com
Operating system: Windows XP
PHP version:      4.3.4
PHP Bug Type:     Class/Object related
Bug description:  inconsistency of unserializing references

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 bug report at http://bugs.php.net/?id=27336&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=27336&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=27336&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=27336&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=27336&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=27336&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=27336&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=27336&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=27336&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=27336&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=27336&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=27336&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=27336&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=27336&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=27336&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=27336&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=27336&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=27336&r=float

Reply via email to