#28082 [NEW]: __sleep() reproducible serialization bug (at least i hope so)
| From: | mastabog at hotmail dot com | Date: | Tue, 20 Apr 2004 19:12:27 +0000 |
| Subject: | #28082 [NEW]: __sleep() reproducible serialization bug (at least i hope so) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-58470@lists.php.net to get a copy of this message | ||
From: mastabog at hotmail dot com
Operating system: Win32, Linux and on all tested
PHP version: 5CVS-2004-04-20 (dev)
PHP Bug Type: Zend Engine 2 problem
Bug description: __sleep() reproducible serialization bug (at least i hope so)
Description:
------------
I posted this as a comment to an existing bug report (after it has been
suspended). The bug report is 4 months old and can be found here:
http://bugs.php.net/bug.php?id=26737
Everything written there (including the last comment which is mine) is
still true, unfortunately.
That bug existed since my first attempt to use __sleep() in PHP5 (approx 1
year ago) and persisted since (i alway use the daily php5-cvs version)
Here is a summary (though I suggest you take a look at the original bug at
the link above).
__sleep() serialization does not work unless you do this: You not only
have to enclose the class name with null characters. As far as I've seen
you have to enclose with
null chars *ALL* Php5 serialization identifiers of class properties types,
the ones I figured out to be for now. The string that needs to be enclosed
in null chars is (let x be the property name):
1. class name, if x is 'private' (i.e. "\0" . __CLASS__ . "\0x")
2. *, if x is 'protected' (i.e. "\0*\0x")
3. Null, if x is 'public' => (i.e. "x")
Here's what I mean (this is how it should be done in order to work ...
meaning to avoid/workaround this bug):
<?php
class aTest
{
public $a = 'one';
protected $b = 'two';
private $c = 'three';
private $d = 'something you dont wanna save';
function __sleep()
{
return array("a",
"\0*\0b",
"\0aTest\0c");
// or
// return array("a",
// "\0*\0b",
// "\0" . __CLASS__ . "\0c");
}
}
?>
Anything else in the return array of __sleep() and the property will
come up empty after unserialization ... not nice.
My hope is that this *is* a bug, because forming those strings with null
chars is just, well, ugly and inconsistent.
Reproduce code:
---------------
<?php
class aTest
{
public $a = 'one';
protected $b = 'two';
private $c = 'three';
private $d = 'something you dont wanna save';
function __sleep()
{
return array("a",
"\0*\0b",
"\0aTest\0c");
}
// This is how it should be, IMHO (php4 style)
//function __sleep()
//{
// return array("a", "b", "c");
//}
}
?>
Expected result:
----------------
With the 2nd __sleep() uncommented you should get the normal serialized
properties of the object. Instead, every private/protected members come up
emtpy.
--
Edit bug report at http://bugs.php.net/?id=28082&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28082&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28082&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28082&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28082&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28082&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28082&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28082&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28082&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28082&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28082&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28082&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28082&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28082&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28082&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28082&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28082&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28082&r=float