|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-11-03 08:13 UTC] i088 at informatik dot fh-wuerzburg dot de
serialize() works not correct with cascaded objects in some circumstances (on PHP 3.0.1x this worked correct !!) :
You have an object whitch contains "normal" variables like integers, strings and also other objects. These other objects also contains integers, strings etc. and again objects:
object 1 --- variable 11
|- variable 12
| :
|- variable 1x
|- object 2 --- variable 21
|- variable 22
| :
|- variable 2x
|- object 3 --- variable 31
| :
|- variable 3x
Under some circumstances the output that serialize() produces does only contain the top-level object (object 1)with its "normal" variables (variable 11 ... variable 1x). The other objects (object 2 and 3) with all there variables are lost.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 04:00:01 2025 UTC |
Here the script: ------------------------cut here---------------------------- <html> <head> <title>Serialize-Test</title> </head> <body> <?php class MetaClass { var $id; var $MainClassObject; } class MainClass { var $id; var $SubClassObjectArray; } class SubClass { var $id; var $Item; } function MainClass_addSubClassObject(&$MainClassReference, $SubClassObject) { $MainClassReference->SubClassObjectArray[]=$SubClassObject; } $myMetaClass=new MetaClass; $myMetaClass->id=uniqid(""); $myMainClass=new MainClass; $myMainClass->id=uniqid(""); $myMetaClass->MainClassObject=$myMainClass; $mySubClass1=new SubClass; $mySubClass1->id=uniqid(""); $mySubClass1->Item="SubClass 1"; MainClass_addSubClassObject($myMetaClass->MainClassObject, $mySubClass1); $mySubClass2=new SubClass; $mySubClass2->id=uniqid(""); $mySubClass2->Item="SubClass 2"; MainClass_addSubClassObject($myMetaClass->MainClassObject, $mySubClass2); $myoldMainClass=$myMetaClass->MainClassObject; $myoldSubClass=reset($myoldMainClass->SubClassObjectArray); while ($myoldSubClass) { print $myoldSubClass->id."----".$myoldSubClass->Item."<br>\n"; $myoldSubClass=next($myoldMainClass->SubClassObjectArray); } print "<br>\n"; $serialized_data=serialize($myMetaClass); print $serialized_data."<br>\n"; print "<br>\n"; $unserialized_data=unserialize($serialized_data); $mynewMainClass=$unserialized_data->MainClassObject; $mynewSubClass=reset($mynewMainClass->SubClassObjectArray); while ($mynewSubClass) { print $mynewSubClass->id."----".$mynewSubClass->Item."<br>\n"; $mynewSubClass=next($mynewMainClass->SubClassObjectArray); } ?> </body> </html> ------------------------cut here----------------------------