From: Nikita Popov Date: Sun, 21 Feb 2016 11:59:57 +0000 (+0100) Subject: Fixed bug #71617 X-Git-Tag: php-7.0.5RC1~87 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0bd64b50b88d243cf337e0c5dbea20e4ba809117;p=php Fixed bug #71617 --- diff --git a/NEWS b/NEWS index 8ae5659192..0cd6c4bc7f 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,10 @@ PHP NEWS - phpdbg: . Fixed crash when advancing (except step) inside an internal function. (Bob) +- SPL: + . Fixed bug #71617 (private properties lost when unserializing ArrayObject). + (Nikita) + ?? Mar 2016 PHP 7.0.4 - Core: diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 2238bcb5e0..a7d19f9892 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -1226,8 +1226,15 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties) size_t prop_name_len; if (zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_name_len) == SUCCESS) { zend_string *pname = zend_string_init(prop_name, prop_name_len, 0); + zend_class_entry *prev_scope = EG(scope); + if (class_name && class_name[0] != '*') { + zend_string *cname = zend_string_init(class_name, strlen(class_name), 0); + EG(scope) = zend_lookup_class(cname); + zend_string_release(cname); + } property_info = zend_get_property_info(object->ce, pname, 1); zend_string_release(pname); + EG(scope) = prev_scope; } else { property_info = ZEND_WRONG_PROPERTY_INFO; } diff --git a/ext/spl/tests/bug71617.phpt b/ext/spl/tests/bug71617.phpt new file mode 100644 index 0000000000..412f83f541 --- /dev/null +++ b/ext/spl/tests/bug71617.phpt @@ -0,0 +1,50 @@ +--TEST-- +Bug #71617: private properties lost when unserializing ArrayObject +--FILE-- +name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } +} + +$test = new Test(['a' => 'a', 'b' => 'b']); +$test->setName('ok'); + +$ser = serialize($test); +$unSer = unserialize($ser); + +var_dump($unSer->getName()); +var_dump($unSer); + +?> +--EXPECT-- +string(2) "ok" +object(Test)#2 (2) { + ["name":"Test":private]=> + string(2) "ok" + ["storage":"ArrayObject":private]=> + array(2) { + ["a"]=> + string(1) "a" + ["b"]=> + string(1) "b" + } +}