Bug #51938 [Opn->Bgs]: serializing an object that implements serializable
Edit report at http://bugs.php.net/bug.php?id=51938&edit=1
ID: 51938
Updated by: johannes@php.net
Reported by: phil dot brookes at gmail dot com
Summary: serializing an object that implements serializable
-Status: Open
+Status: Bogus
Type: Bug
Package: SPL related
Operating System: CentOS kernel 2.6.18-164.11.1
PHP Version: 5.3.2
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
The serialize() method of an object implementing Serializable is called
by serialize() so you get an recursion. you have to implement
Serializable only when you want do use your own serialization logic for
your class.
The serialize() method of the object shall not be called directly but by
PHP's serializer.
serialize($serializable);
Your code gives infinite recursion. Infinite recursion is known to lead
to a stack overflow.
Previous Comments:
------------------------------------------------------------------------
[2010-05-28 00:37:50] phil dot brookes at gmail dot com
Description:
------------
Hello,
Create a class and implement Serializable, then use the serialize
function to return the value of serialize($this), apache crashes with an
internal server error, the apache error log reports a Premature end of
script headers error.
If line 17 is commented then the apache server does not crash.
Test script:
---------------
<?php
/**Simple class that is serializable and implements the serializable
interface */
class ImplementsSerializable implements Serializable {
/** returns the serialization of itself */
public function serialize() {
return serialize($this);
}
/** returns unserialized object passed in $serialized */
public function unserialize($serialized) {
return unserialize($serialized);
}
}
/** Create a new ImplementSerializable object */
$serializable = new ImplementsSerializable();
/** Store the serialized value in $serialized, this causes apache to
crash, with a
* Premature end of script headers error in the apache error log */
$serialized = $serializable->serialize();
/**point of execution does not reach here */
$unserialized = $serializable->unserialize($serialized);
echo "finished!";
?>
Expected result:
----------------
return value equal to the object serialized using the serialize
function.
Actual result:
--------------
Apache crashes with internal server error and a Premature end of script
headers error.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51938&edit=1
Thread (2 messages)