Skip to content

Commit 63be66b

Browse files
committed
Fix crash on PropertyReflection::{get,set}RawValue() on dynamic prop
1 parent 77615a5 commit 63be66b

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

ext/reflection/php_reflection.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5851,7 +5851,7 @@ ZEND_METHOD(ReflectionProperty, getRawValue)
58515851
RETURN_THROWS();
58525852
}
58535853

5854-
if (!ref->prop->hooks || !ref->prop->hooks[ZEND_PROPERTY_HOOK_GET]) {
5854+
if (!ref->prop || !ref->prop->hooks || !ref->prop->hooks[ZEND_PROPERTY_HOOK_GET]) {
58555855
zval rv;
58565856
zval *member_p = zend_read_property_ex(intern->ce, Z_OBJ_P(object), ref->unmangled_name, 0, &rv);
58575857

@@ -5887,7 +5887,7 @@ ZEND_METHOD(ReflectionProperty, setRawValue)
58875887
RETURN_THROWS();
58885888
}
58895889

5890-
if (!ref->prop->hooks || !ref->prop->hooks[ZEND_PROPERTY_HOOK_SET]) {
5890+
if (!ref->prop || !ref->prop->hooks || !ref->prop->hooks[ZEND_PROPERTY_HOOK_SET]) {
58915891
zend_update_property_ex(intern->ce, Z_OBJ_P(object), ref->unmangled_name, value);
58925892
} else {
58935893
zend_function *func = zend_get_property_hook_trampoline(ref->prop, ZEND_PROPERTY_HOOK_SET, ref->unmangled_name);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
ReflectionProperty::{get,set}RawValue() crashes on dynamic properties
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public $a;
8+
}
9+
10+
$a = new A();
11+
$b = new A();
12+
$b->dyn = 1;
13+
14+
$prop = new ReflectionProperty($b, 'dyn');
15+
var_dump($prop->getRawValue($a));
16+
$prop->setRawValue($a, 1);
17+
18+
?>
19+
--EXPECTF--
20+
Deprecated: Creation of dynamic property A::$dyn is deprecated in %s on line %d
21+
22+
Warning: Undefined property: A::$dyn in %s on line %d
23+
NULL
24+
25+
Deprecated: Creation of dynamic property A::$dyn is deprecated in %s on line %d

0 commit comments

Comments
 (0)