note 60317 added to function.serialize
| From: | MC_Gurk at gmx dot net | Date: | Tue, 03 Jan 2006 15:44:56 +0000 |
| Subject: | note 60317 added to function.serialize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-101152@lists.php.net to get a copy of this message | ||
If you are going to serialie an object which contains references to other objects you want to
serialize some time later, these references will be lost when the object is unserialized.
The references can only be kept if all of your objects are serialized at once.
That means:
$a = new ClassA();
$b = new ClassB($a); //$b containes a reference to $a;
$s1=serialize($a);
$s2=serialize($b);
$a=unserialize($s1);
$b=unserialize($s2);
now b references to an object of ClassA which is not $a. $a is another object of Class A.
use this:
$buf[0]=$a;
$buf[1]=$b;
$s=serialize($buf);
$buf=unserialize($s);
$a=$buf[0];
$b=$buf[1];
all references are intact.
----
Manual Page -- http://www.php.net/manual/en/function.serialize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60317
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60317&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60317&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60317&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60317&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60317&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60317&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60317&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60317&report=yes
Search -- http://master.php.net/manage/user-notes.php