Doc #50793 [Ver->Csd]: Note about not being able to serialize internal objects needs clarifiaction

From: Date: Wed, 20 Oct 2010 06:52:42 +0000
Subject: Doc #50793 [Ver->Csd]: 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-5278@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=50793&edit=1 ID: 50793 Updated by: kalle@php.net Reported by: weirdan at gmail dot com Summary: Note about not being able to serialize internal objects needs clarifiaction -Status: Verified +Status: Closed Type: Documentation Problem Package: Documentation problem PHP Version: 5.3.1 -Assigned To: +Assigned To: kalle Block user comment: N New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. Previous Comments: ------------------------------------------------------------------------ [2010-10-20 08:52:34] kalle@php.net Automatic comment from SVN on behalf of kalle Revision: http://svn.php.net/viewvc/?view=revision&revision=304536 Log: Fixed bug #50793 (Note about not being able to serialize internal objects needs clarifiaction) ------------------------------------------------------------------------ [2010-01-19 00:17:39] weirdan at gmail dot com 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$ ------------------------------------------------------------------------ [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/bug.php?id=50793&edit=1

« previous php.doc.bugs (#5278) next »