|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69210 serialize function return corrupted data when sleep has non-string values
Submitted: 2015-03-10 03:59 UTC Modified: 2015-03-23 03:37 UTC
From: jrbasso at gmail dot com Assigned: stas (profile)
Status: Closed Package: *General Issues
PHP Version: 5.6.6 OS: Any
Private report: No CVE-ID: None
 [2015-03-10 03:59 UTC] jrbasso at gmail dot com
When serializing an object that has a sleep method and this method returns a non-string value the value generated by serialize is corrupted and can't be unserialized.

It works fine with values that are strings but not attribute (see, but it doesn't with non-string values (see or the test script below).

HHVM works fine with non-strings. I wrote a patch that makes the PHP to works the same way (patch attached and available on

Test script:

class C {
	public $a = true;

	public function __sleep() {
		return ['a', 1];

$a = new C;

$s = serialize($a);

Expected result:
Notice: serialize(): "1" returned as member variable from __sleep() but does not exist in /in/81nem on line 13
string(30) "O:1:"C":2:{s:1:"a";b:1;i:1;N;}"
object(C)#2 (2) {

Actual result:
Notice: serialize(): __sleep should return an array only containing the names of instance-variables to serialize. in /in/81nem on line 13
string(26) "O:1:"C":2:{s:1:"a";b:1;N;}"

Notice: unserialize(): Error at offset 25 of 26 bytes in /in/81nem on line 15


PR-1057.patch (last revision 2015-03-10 04:04 UTC by jrbasso at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-03-23 03:37 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2015-03-23 03:37 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 01:01:29 2024 UTC