Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions ext/standard/tests/serialize/bug69210.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
--TEST--
serialize() integrity with non string on __sleep
--FILE--
<?php
class testString
{
public $a = true;

public function __sleep()
{
return array('a', '1');
}
}

class testInteger
{
public $a = true;

public function __sleep()
{
return array('a', 1);
}
}

$cs = new testString();
$ci = new testInteger();

$ss = @serialize($cs);
echo $ss . "\n";

$si = @serialize($ci);
echo $si . "\n";

var_dump(unserialize($ss));
var_dump(unserialize($si));
?>
--EXPECT--
O:10:"testString":2:{s:1:"a";b:1;s:1:"1";N;}
O:11:"testInteger":2:{s:1:"a";b:1;s:1:"1";N;}
object(testString)#3 (2) {
["a"]=>
bool(true)
["1"]=>
NULL
}
object(testInteger)#3 (2) {
["a"]=>
bool(true)
["1"]=>
NULL
}
5 changes: 1 addition & 4 deletions ext/standard/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,10 +705,7 @@ static void php_var_serialize_class(smart_str *buf, zval *struc, zval *retval_pt

if (Z_TYPE_P(name) != IS_STRING) {
php_error_docref(NULL, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize.");
/* we should still add element even if it's not OK,
* since we already wrote the length of the array before */
smart_str_appendl(buf,"N;", 2);
continue;
convert_to_string(name);
}
propers = Z_OBJPROP_P(struc);
if ((d = zend_hash_find(propers, Z_STR_P(name))) != NULL) {
Expand Down