1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix incorrect handling of hooked props without get hook in get_object_vars()

Fixes GH-17988
Closes GH-17997
This commit is contained in:
Ilija Tovilo
2025-03-07 20:47:43 +01:00
parent 8950c241b3
commit 868959350f
4 changed files with 44 additions and 4 deletions

2
NEWS
View File

@@ -13,6 +13,8 @@ PHP NEWS
results for closures created from magic __call()). (timwolla)
. Fixed bug GH-17941 (Stack-use-after-return with lazy objects and hooks).
(nielsdos)
. Fixed bug GH-17988 (Incorrect handling of hooked props without get hook in
get_object_vars()). (ilutov)
- DOM:
. Fixed bug GH-17991 (Assertion failure dom_attr_value_write). (nielsdos)

View File

@@ -0,0 +1,40 @@
--TEST--
GH-17988: Incorrect handling of hooked properties without get hook in get_object_vars()
--FILE--
<?php
class C
{
public string $prop {
set => $value;
}
}
$c = new C;
$c->prop = 42;
var_dump($c);
var_dump(get_object_vars($c));
var_export($c);
echo "\n";
var_dump(json_encode($c));
var_dump((array)$c);
?>
--EXPECTF--
object(C)#%d (1) {
["prop"]=>
string(2) "42"
}
array(1) {
["prop"]=>
string(2) "42"
}
\C::__set_state(array(
'prop' => '42',
))
string(13) "{"prop":"42"}"
array(1) {
["prop"]=>
string(2) "42"
}

View File

@@ -840,7 +840,7 @@ ZEND_FUNCTION(get_object_vars)
}
const char *unmangled_name_cstr = zend_get_unmangled_property_name(prop_info->name);
zend_string *unmangled_name = zend_string_init(unmangled_name_cstr, strlen(unmangled_name_cstr), false);
zend_read_property_ex(prop_info->ce, zobj, unmangled_name, /* silent */ true, &tmp);
value = zend_read_property_ex(prop_info->ce, zobj, unmangled_name, /* silent */ true, &tmp);
zend_string_release_ex(unmangled_name, false);
if (EG(exception)) {
zend_release_properties(properties);
@@ -848,7 +848,6 @@ ZEND_FUNCTION(get_object_vars)
ZVAL_UNDEF(return_value);
RETURN_THROWS();
}
value = &tmp;
}
Z_TRY_ADDREF_P(value);

View File

@@ -283,13 +283,12 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
if ((prop_info->flags & ZEND_ACC_VIRTUAL) && !prop_info->hooks[ZEND_PROPERTY_HOOK_GET]) {
continue;
}
zend_read_property_ex(prop_info->ce, Z_OBJ_P(val), prop_info->name, /* silent */ true, &tmp);
data = zend_read_property_ex(prop_info->ce, Z_OBJ_P(val), prop_info->name, /* silent */ true, &tmp);
if (EG(exception)) {
PHP_JSON_HASH_UNPROTECT_RECURSION(recursion_rc);
zend_release_properties(prop_ht);
return FAILURE;
}
data = &tmp;
}
if (need_comma) {