Skip to content

Commit 048fa7b

Browse files
committed
Fix get_object_vars() for non-hooked props in hooked prop iter
The zend_hash_update_ind() variant unwraps indirects, rather than creating them. Don't use _zend_hash_append_ind() because the property might already exist. Fixes GH-16725 Closes GH-16805
1 parent 159b71c commit 048fa7b

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88

99
- Core:
1010
. Fail early in *nix configuration build script. (hakre)
11+
. Fixed bug GH-16725 (Incorrect access check for non-hooked props in hooked
12+
object iterator). (ilutov)
1113

1214
- Curl:
1315
. Fixed bug GH-16723 (CURLMOPT_PUSHFUNCTION issues). (cmb)

Zend/tests/gh16725.phpt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-16725: Incorrect access check for non-hooked props in hooked object iterator
3+
--FILE--
4+
<?php
5+
6+
class C implements JsonSerializable
7+
{
8+
private string $prop1 { get => 'bar'; }
9+
10+
public function __construct(
11+
private string $prop2,
12+
) {}
13+
14+
public function jsonSerialize(): mixed {
15+
return get_object_vars($this);
16+
}
17+
}
18+
19+
$obj = new C('foo');
20+
var_dump(get_object_vars($obj));
21+
echo json_encode($obj);
22+
23+
?>
24+
--EXPECT--
25+
array(0) {
26+
}
27+
{"prop1":"bar","prop2":"foo"}

Zend/zend_property_hooks.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ static zend_array *zho_build_properties_ex(zend_object *zobj, bool check_access,
8989
if (UNEXPECTED(Z_TYPE_P(OBJ_PROP(zobj, prop_info->offset)) == IS_UNDEF)) {
9090
HT_FLAGS(properties) |= HASH_FLAG_HAS_EMPTY_IND;
9191
}
92-
zend_hash_update_ind(properties, property_name, OBJ_PROP(zobj, prop_info->offset));
92+
zval *tmp = zend_hash_lookup(properties, property_name);
93+
ZVAL_INDIRECT(tmp, OBJ_PROP(zobj, prop_info->offset));
9394
}
9495
skip_property:
9596
if (property_name != prop_info->name) {

0 commit comments

Comments
 (0)