PHP 4.0 Bug #8224: serialize() fails on arrays of objects
| From: | stefan dot andreatta at uibk dot ac dot at | Date: | Wed, 13 Dec 2000 12:08:19 +0000 |
| Subject: | PHP 4.0 Bug #8224: serialize() fails on arrays of objects | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-41164@lists.php.net to get a copy of this message | ||
From: stefan.andreatta@uibk.ac.at
Operating system: Win 2000 pro, IIS 5
PHP version: 4.0.3pl1
PHP Bug Type: Variables related
Bug description: serialize() fails on arrays of objects
If an array of objects is serialized/unserialized the array looses those elements (objects) for
which a method has been called before serialization.
This bug occurs in version 4.0.3pl1, but disappears when the php4ts.dll is exchanged for version
4.0.2 (no other changes to the installation required).
This bug could be linked to #7619. Unfortunately I can't compile a Windows .dll at the moment,
so I can't check with the CVS.
The following samples script defines a simple class with one property and one method. Then an array
is created containing two instances of this class. After calling the object's method for
element[1] the array is serialized/unserialized. After that it contains only 1 element.
-- script ----------------------------------------------
<?php
class TestClass
{
function TestClass ($a)
{
$this->property = $a;
}
function getProperty ()
{
return $this->property;
}
}
//create instance
$testArr[] = new TestClass("content 1");
$testArr[] = new TestClass("content 2");
$testArr[1]->getProperty();
$unser = unserialize(serialize($testInst));
echo "Before Serialization:";
echo "<br>number of elements: " . count($testArr);
echo "<br>property of element[0]: " . $testArr[0]->property;
echo "<br>property of element[1]: " . $testArr[1]->property;
echo "<br><br>After Serialization:";
echo "<br>number of elements: " . count($unser);
echo "<br>property of element[0]: " . $unser[0]->property;
echo "<br>property of element[1]: " . $unser[1]->property;
?>
-- end of script ----------------------------------------
--
Edit Bug report at: http://bugs.php.net/?id=8224&edit=1