#50793 [Ver]: Note about not being able to serialize internal objects needs clarifiaction
| From: | weirdan at gmail dot com | Date: | Tue, 19 Jan 2010 00:17:40 +0000 |
| Subject: | #50793 [Ver]: Note about not being able to serialize internal objects needs clarifiaction | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3748@lists.php.net to get a copy of this message | ||
ID: 50793
User updated by: weirdan at gmail dot com
Reported By: weirdan at gmail dot com
Status: Verified
Bug Type: Documentation problem
PHP Version: 5.3.1
New Comment:
It's not that simple. For example ArrayObject in 5.3.1 does implement
Serializable, but it did not back in 5.2.12 (latest stable 5.2) - and
yet
serialize/unserialize worked on it quite well:
weirdan@virtual-debian:/home/sam/trunk$ sudo update-alternatives --set
php /usr/bin/php5
update-alternatives: using /usr/bin/php5 to provide /usr/bin/php (php)
in manual mode.
weirdan@virtual-debian:/home/sam/trunk$ php -r
'var_dump(phpversion());
$c = new ReflectionClass("ArrayObject");
var_dump("is internal", $c->isInternal());
$q = new ArrayObject(array(1,2,3));
$w = unserialize(serialize($q));
assert("\$q[1] == \$w[1]");
var_dump("past assert");
var_dump("has __sleep or __wakeup", $c->hasMethod("__sleep") or
$c->hasMethod("__wakeup"));
var_dump("implements Serializable",
$c->implementsInterface("Serializable"));'
string(8) "5.2.12-2"
string(11) "is internal"
bool(true)
string(11) "past assert"
string(23) "has __sleep or __wakeup"
bool(false)
string(23) "implements Serializable"
bool(false)
weirdan@virtual-debian:/home/sam/trunk$
Previous Comments:
------------------------------------------------------------------------
[2010-01-18 19:33:53] bjori@php.net
$ php -n -r '$d = new DOMDocument("1.0", "UTF-8"); $s = serialize($d);
var_dump(unserialize($s)->encoding, $d->encoding);'
Warning: Unknown: Invalid State Error in Command line code on line 1
NULL
string(5) "UTF-8"
See bug#30323 &&
http://svn.php.net/viewvc/phpdoc/en/trunk/reference/var/functions/seri
alize.xml?r1=164053&r2=172271
I guess the simplest way to fix this is to say something along the
lines of "classes that do not implement Serializable or the
__sleep()/__wakeUp() functions cannot be reliably serialized"?
------------------------------------------------------------------------
[2010-01-18 19:16:09] weirdan at gmail dot com
Description:
------------
Manual says 'It is not possible to serialize PHP built-in objects',
however some of internal classes support serialization:
weirdan@virtual-debian:/home/sam/trunk$ php -r
'var_dump(phpversion());
$c = new ReflectionClass("ArrayObject");
var_dump("is internal", $c->isInternal());
$q = new ArrayObject();
var_dump(serialize($q));'
string(5) "5.3.1"
string(11) "is internal"
bool(true)
string(45) "C:11:"ArrayObject":21:{x:i:0;a:0:{};m:a:0:{}}"
weirdan@virtual-debian:/home/sam/trunk$
Reproduce code:
---------------
---
From manual page: function.serialize#Notes
---
See description
Expected result:
----------------
Explicitly list serializable/non-serializable classes for extensions
enabled by default (possibly in appendix).
Actual result:
--------------
The note is misleading.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50793&edit=1