Skip to content
Closed
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
40 changes: 40 additions & 0 deletions Zend/tests/property_hooks/gh17988.phpt
Original file line number Diff line number Diff line change
@@ -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"
}
3 changes: 1 addition & 2 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,15 +840,14 @@ 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);
zval_ptr_dtor(return_value);
ZVAL_UNDEF(return_value);
RETURN_THROWS();
}
value = &tmp;
}
Z_TRY_ADDREF_P(value);

Expand Down
3 changes: 1 addition & 2 deletions ext/json/json_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading