PHP 4.0 Bug #8224 Updated: serialize() fails on arrays of objects
| From: | stefan dot andreatta at uibk dot ac dot at | Date: | Thu, 14 Dec 2000 10:26:22 +0000 |
| Subject: | PHP 4.0 Bug #8224 Updated: serialize() fails on arrays of objects | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-41320@lists.php.net to get a copy of this message | ||
ID: 8224
User Update by: stefan.andreatta@uibk.ac.at
Status: Bogus
Bug Type: Variables related
Description: serialize() fails on arrays of objects
Sorry. There is in fact a mistake in line 20, which should serialize $testArr not $testInst.
However, this does not affect the described Problem
Stefan
The correct script is:
--- 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($testArr));
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 script --------------------------------------------
Previous Comments:
---------------------------------------------------------------------------
[2000-12-13 19:27:35] waldschrott@php.net
bogus, it is an error the user script
---------------------------------------------------------------------------
[2000-12-13 08:21:57] jmoore@php.net
The serialize bugs have been fixed in CVS. Please upgrade to 4.0.4 when it is avaible (you can get
last RC *very stable* from ftp.phpuk.org)
James
---------------------------------------------------------------------------
[2000-12-13 07:08:19] stefan.andreatta@uibk.ac.at
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 ----------------------------------------
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=8224