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
12 changes: 9 additions & 3 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -6505,7 +6505,8 @@ ZEND_METHOD(ReflectionProperty, getHooks)

GET_REFLECTION_OBJECT_PTR(ref);

if (!ref->prop->hooks) {
// ref->prop can be missing for dynamic properties
if (!ref->prop || !ref->prop->hooks) {
RETURN_EMPTY_ARRAY();
}

Expand Down Expand Up @@ -6536,11 +6537,16 @@ ZEND_METHOD(ReflectionProperty, getHook)

GET_REFLECTION_OBJECT_PTR(ref);

// ref->prop can be missing for dynamic properties
if (!ref->prop || !ref->prop->hooks) {
RETURN_NULL();
}

zend_function *hook;
if (zend_string_equals_literal(Z_STR_P(zend_enum_fetch_case_name(type)), "Get")) {
hook = ref->prop->hooks ? ref->prop->hooks[ZEND_PROPERTY_HOOK_GET] : NULL;
hook = ref->prop->hooks[ZEND_PROPERTY_HOOK_GET];
} else {
hook = ref->prop->hooks ? ref->prop->hooks[ZEND_PROPERTY_HOOK_SET] : NULL;
hook = ref->prop->hooks[ZEND_PROPERTY_HOOK_SET];
}

if (!hook) {
Expand Down
48 changes: 48 additions & 0 deletions ext/reflection/tests/property_hooks/gh15718.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
--TEST--
ReflectionProperty::get{Hook,Hooks}() crashes on dynamic properties
--FILE--
<?php

#[\AllowDynamicProperties]
class MyDynamicClass {

}

class NonDynamicClass {

}

$cases = [ MyDynamicClass::class, stdClass::class, NonDynamicClass::class ];

foreach ( $cases as $c ) {
echo "$c:" . PHP_EOL;
$obj = new $c();
$obj->prop = 'foo';
$prop = new ReflectionProperty($obj, 'prop');
var_dump( $prop->getHooks() );
var_dump( $prop->getHook( PropertyHookType::Get ) );
var_dump( $prop->getHook( PropertyHookType::Set ) );
echo PHP_EOL;
}

?>
--EXPECTF--
MyDynamicClass:
array(0) {
}
NULL
NULL

stdClass:
array(0) {
}
NULL
NULL

NonDynamicClass:

Deprecated: Creation of dynamic property NonDynamicClass::$prop is deprecated in %sgh15718.php on line %d
array(0) {
}
NULL
NULL
Loading