|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-01-18 19:16 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 21:00:01 2025 UTC |
$ 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"?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$