File tree Expand file tree Collapse file tree 3 files changed +59
-3
lines changed Expand file tree Collapse file tree 3 files changed +59
-3
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ PHP NEWS
16
16
property. (ilutov)
17
17
. Fixed bug GH-15693 (Unnecessary include in main.c bloats binary).
18
18
(nielsdos)
19
+ . Fixed bug GH-15718 (Segfault on ReflectionProperty::get{Hook,Hooks}() on
20
+ dynamic properties). (DanielEScherzer)
19
21
20
22
- DOM:
21
23
. Fixed bug GH-13988 (Storing DOMElement consume 4 times more memory in
Original file line number Diff line number Diff line change @@ -6505,7 +6505,8 @@ ZEND_METHOD(ReflectionProperty, getHooks)
6505
6505
6506
6506
GET_REFLECTION_OBJECT_PTR (ref );
6507
6507
6508
- if (!ref -> prop -> hooks ) {
6508
+ // ref->prop can be missing for dynamic properties
6509
+ if (!ref -> prop || !ref -> prop -> hooks ) {
6509
6510
RETURN_EMPTY_ARRAY ();
6510
6511
}
6511
6512
@@ -6536,11 +6537,16 @@ ZEND_METHOD(ReflectionProperty, getHook)
6536
6537
6537
6538
GET_REFLECTION_OBJECT_PTR (ref );
6538
6539
6540
+ // ref->prop can be missing for dynamic properties
6541
+ if (!ref -> prop || !ref -> prop -> hooks ) {
6542
+ RETURN_NULL ();
6543
+ }
6544
+
6539
6545
zend_function * hook ;
6540
6546
if (zend_string_equals_literal (Z_STR_P (zend_enum_fetch_case_name (type )), "Get" )) {
6541
- hook = ref -> prop -> hooks ? ref -> prop -> hooks [ZEND_PROPERTY_HOOK_GET ] : NULL ;
6547
+ hook = ref -> prop -> hooks [ZEND_PROPERTY_HOOK_GET ];
6542
6548
} else {
6543
- hook = ref -> prop -> hooks ? ref -> prop -> hooks [ZEND_PROPERTY_HOOK_SET ] : NULL ;
6549
+ hook = ref -> prop -> hooks [ZEND_PROPERTY_HOOK_SET ];
6544
6550
}
6545
6551
6546
6552
if (!hook ) {
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ ReflectionProperty::get{Hook,Hooks}() crashes on dynamic properties
3
+ --FILE--
4
+ <?php
5
+
6
+ #[\AllowDynamicProperties]
7
+ class MyDynamicClass {
8
+
9
+ }
10
+
11
+ class NonDynamicClass {
12
+
13
+ }
14
+
15
+ $ cases = [ MyDynamicClass::class, stdClass::class, NonDynamicClass::class ];
16
+
17
+ foreach ( $ cases as $ c ) {
18
+ echo "$ c: " . PHP_EOL ;
19
+ $ obj = new $ c ();
20
+ $ obj ->prop = 'foo ' ;
21
+ $ prop = new ReflectionProperty ($ obj , 'prop ' );
22
+ var_dump ( $ prop ->getHooks () );
23
+ var_dump ( $ prop ->getHook ( PropertyHookType::Get ) );
24
+ var_dump ( $ prop ->getHook ( PropertyHookType::Set ) );
25
+ echo PHP_EOL ;
26
+ }
27
+
28
+ ?>
29
+ --EXPECTF--
30
+ MyDynamicClass:
31
+ array(0) {
32
+ }
33
+ NULL
34
+ NULL
35
+
36
+ stdClass:
37
+ array(0) {
38
+ }
39
+ NULL
40
+ NULL
41
+
42
+ NonDynamicClass:
43
+
44
+ Deprecated: Creation of dynamic property NonDynamicClass::$prop is deprecated in %sgh15718.php on line %d
45
+ array(0) {
46
+ }
47
+ NULL
48
+ NULL
You can’t perform that action at this time.
0 commit comments