PHP 4.0 Bug #7619 Updated: serialize() works not correct with cascaded objects in some circumstances
| From: | i088 at informatik dot fh-wuerzburg dot de | Date: | Wed, 29 Nov 2000 21:13:49 +0000 |
| Subject: | PHP 4.0 Bug #7619 Updated: serialize() works not correct with cascaded objects in some circumstances | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-39631@lists.php.net to get a copy of this message | ||
ID: 7619
User Update by: i088@informatik.fh-wuerzburg.de
Old-Status: Closed
Status: Open
Bug Type: Variables related
Description: serialize() works not correct with cascaded objects in some circumstances
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----------------------------
Previous Comments:
---------------------------------------------------------------------------
[2000-11-29 06:37:15] sniper@php.net
No feedback.
---------------------------------------------------------------------------
[2000-11-05 06:31:43] stas@php.net
Could you please provide some short example code?
---------------------------------------------------------------------------
[2000-11-03 08:13:04] i088@informatik.fh-wuerzburg.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.
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=7619