note 52114 added to language.oop.serialization

From: Date: Thu, 21 Apr 2005 12:51:29 +0000
Subject: note 52114 added to language.oop.serialization
Groups: php.notes 
Request: Send a blank email to php-notes+get-88348@lists.php.net to get a copy of this message
Was wondering, if References are also lost after serializing and deserializing in php5. Wrote a testfile and my result is: All references are restored corretly. Even if the classes where recursively referenced. Here is the code of the file: <? //check refereneces class A { public $a_var; /** * @var B */ public $parent; public function __construct($parent) { $this->parent=$parent; } } class B { /** * @var A */ public $Ref_auf_A; /** * @var A */ public $aObj; public $name=""; public function __construct($InhaltA) { $this->aObj=new A($this); $this->aObj->a_var=$InhaltA; $this->Ref_auf_A=$this->aObj; } } $B_obj = new B("Inhalt von A"); $B_obj->name="My is <defaultName>"; echo "Object B before serializing:<pre>"; print_r($B_obj); echo "</pre><br><br>"; $serB=serialize($B_obj); echo "Object B serialized: ".$serB."<br><br>"; $B_obj = unserialize($serB); echo "Object B deserializedt:<pre>"; print_r($B_obj); echo "</pre><br><br>"; $B_obj->Ref_auf_A->a_var="Test"; echo "Object A reference content changed, should have changed everywhere:<pre>"; print_r($B_obj); echo "</pre><br><br>"; //Change name of object where A parent references to. $B_obj->Ref_auf_A->parent->name="My name changed"; echo $B_obj->name; ?> ---- Manual Page -- http://www.php.net/manual/en/language.oop.serialization.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52114 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52114&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52114&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52114&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52114&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52114&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52114&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88348) next »