php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #50793 Note about not being able to serialize internal objects needs clarifiaction
Submitted: 2010-01-18 19:16 UTC Modified: 2010-10-20 08:52 UTC
From: weirdan at gmail dot com Assigned: kalle (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: weirdan at gmail dot com
New email:
PHP Version: OS:

 

 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-18 19:33 UTC] 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-19 00:17 UTC] 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-10-20 08:52 UTC] 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-10-20 08:52 UTC] kalle@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: kalle
 [2010-10-20 08:52 UTC] kalle@php.net
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.


 [2020-02-07 06:09 UTC] phpdocbot@php.net
Automatic comment on behalf of kalle
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=0a45b3310f7549655aa0c915afc01c9d85ae74e3
Log: Fixed bug #50793 (Note about not being able to serialize internal objects needs clarifiaction)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC