Bug #68099 [NEW]: Unable to unserialize data after implementing Serializable
| From: | manuel-php at mausz dot at | Date: | Thu, 25 Sep 2014 16:23:52 +0000 |
| Subject: | Bug #68099 [NEW]: Unable to unserialize data after implementing Serializable | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-187700@lists.php.net to get a copy of this message | ||
From: manuel-php at mausz dot at
Operating system:
PHP version: 5.6.1RC1
Package: *General Issues
Bug Type: Bug
Bug description:Unable to unserialize data after implementing Serializable
Description:
------------
Consider the following case:
* User implements class Foo which gets serialized and unserialized
during daily use. Serialized data is stored somewhere.
* User changes class Foo to implement Serializable
* User still wants to transparently unserialize his old data
This worked in PHP5.5 and below. It's broken in PHP 5.6.0 and above.
If this is intended than this is a major BC break not mentioned in the
upgrade guidelines.
Test script:
---------------
<?php
error_reporting(E_ALL);
# export ... simulates exporting old data where class Foo didn't
implement Serializable
$mode = (isset($argv[1]) && $argv[1] === 'import') ? 'import' :
'export';
if ($mode === 'export')
{
class Foo
{
protected $foo = null;
public function __construct()
{
$this->foo = "something";
}
}
$foo = new Foo();
$data = serialize($foo);
file_put_contents('/tmp/phpbug', $data);
}
else
{
class Foo implements Serializable
{
protected $foo = null;
public function __construct()
{
$this->foo = "something";
}
public function serialize()
{
echo __CLASS__ . "::serialize called\n";
return $this->foo;
}
public function unserialize($data)
{
echo __CLASS__ . "::unserialize called\n";
$this->foo = $data;
}
}
$data = file_get_contents('/tmp/phpbug');
$foo = unserialize($data);
if ($foo instanceof Foo)
echo "Thumbs up!\n";
else
echo "Unserialize FAILED\n";
}
Expected result:
----------------
# php5.5 serialize.php export; php5.5 serialize.php import
Thumbs up!
Actual result:
--------------
./php-src-PHP-5.6.1/sapi/cli/php serialize.php export ;
./php-src-PHP-5.6.1/sapi/cli/php serialize.php import
Warning: Erroneous data format for unserializing 'Foo' in
/home/manuel/serialize.php on line 49
Notice: unserialize(): Error at offset 13 of 43 bytes in
/home/manuel/serialize.php on line 49
Unserialize FAILED
--
Edit bug report at https://bugs.php.net/bug.php?id=68099&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68099&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68099&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68099&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68099&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68099&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68099&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68099&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68099&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68099&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68099&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68099&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68099&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68099&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68099&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68099&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68099&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68099&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68099&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68099&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68099&r=mysqlcfg