ID:               27336
 Updated by:       [EMAIL PROTECTED]
 Reported By:      hawcue at yahoo dot com
-Status:           Open
+Status:           Wont fix
 Bug Type:         Class/Object related
 Operating System: Windows XP
 PHP Version:      4.3.4
 New Comment:

Don't mess with references and serializing. That doesn't work and it
won't work.




Previous Comments:
------------------------------------------------------------------------

[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

Reply via email to