mirror of
https://github.com/php/php-src.git
synced 2024-11-25 19:05:31 +08:00
Fixed bug #21957 (serialize() mangles objects with __sleep).
This commit is contained in:
parent
da30777de5
commit
4320c6994f
49
ext/standard/tests/serialize/bug21957.phpt
Normal file
49
ext/standard/tests/serialize/bug21957.phpt
Normal file
@ -0,0 +1,49 @@
|
||||
--TEST--
|
||||
Bug #21957 (serialize() mangles objects with __sleep)
|
||||
--FILE--
|
||||
<?php
|
||||
class test
|
||||
{
|
||||
var $a, $b;
|
||||
|
||||
function test()
|
||||
{
|
||||
$this->a = 7;
|
||||
$this->b = 2;
|
||||
}
|
||||
|
||||
function __sleep()
|
||||
{
|
||||
$this->b = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$t['one'] = 'ABC';
|
||||
$t['two'] = new test();
|
||||
|
||||
var_dump($t);
|
||||
|
||||
$s = @serialize($t);
|
||||
echo $s . "\n";
|
||||
|
||||
var_dump(unserialize($s));
|
||||
?>
|
||||
--EXPECT--
|
||||
array(2) {
|
||||
["one"]=>
|
||||
string(3) "ABC"
|
||||
["two"]=>
|
||||
object(test)#1 (2) {
|
||||
["a"]=>
|
||||
int(7)
|
||||
["b"]=>
|
||||
int(2)
|
||||
}
|
||||
}
|
||||
a:2:{s:3:"one";s:3:"ABC";s:3:"two";N;}
|
||||
array(2) {
|
||||
["one"]=>
|
||||
string(3) "ABC"
|
||||
["two"]=>
|
||||
NULL
|
||||
}
|
@ -483,7 +483,7 @@ static void php_var_serialize_class(smart_str *buf, zval **struc, zval *retval_p
|
||||
"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,"s:0:\"\";N;", 9);
|
||||
smart_str_appendl(buf,"N;", 2);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -565,6 +565,9 @@ static void php_var_serialize_intern(smart_str *buf, zval **struc, HashTable *va
|
||||
php_error_docref(NULL TSRMLS_CC, 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);
|
||||
}
|
||||
|
||||
zval_ptr_dtor(&retval_ptr);
|
||||
|
Loading…
Reference in New Issue
Block a user