Bug #68099 [Opn]: Unable to unserialize data after implementing Serializable
| From: | manuel-php at mausz dot at | Date: | Thu, 25 Sep 2014 20:31:56 +0000 |
| Subject: | Bug #68099 [Opn]: Unable to unserialize data after implementing Serializable | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-187705@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=68099&edit=1
ID: 68099
User updated by: manuel-php at mausz dot at
Reported by: manuel-php at mausz dot at
Summary: Unable to unserialize data after implementing
Serializable
Status: Open
Type: Bug
Package: *General Issues
PHP Version: 5.6.1RC1
Block user comment: N
Private report: N
New Comment:
Reverting c2acdbdd3deb6787329bf0aca8ab0c04ace2a50c fixes this issue
Previous Comments:
------------------------------------------------------------------------
[2014-09-25 16:23:51] manuel-php at mausz dot at
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 this bug report at https://bugs.php.net/bug.php?id=68099&edit=1