File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change @@ -81,6 +81,8 @@ PHP NEWS
81
81
- Reflection:
82
82
. Added ReflectionConstant::getExtension() and ::getExtensionName().
83
83
(DanielEScherzer)
84
+ . Fixed bug GH-12856 (ReflectionClass::getStaticPropertyValue() returns UNDEF
85
+ zval for uninitialized typed properties). (nielsdos)
84
86
85
87
- Session:
86
88
. session_start() throws a ValueError on option argument if not a hashmap
Original file line number Diff line number Diff line change @@ -4128,16 +4128,21 @@ ZEND_METHOD(ReflectionClass, getStaticPropertyValue)
4128
4128
prop = zend_std_get_static_property (ce , name , BP_VAR_IS );
4129
4129
EG (fake_scope ) = old_scope ;
4130
4130
4131
- if (prop ) {
4131
+ if (prop && ! Z_ISUNDEF_P ( prop ) ) {
4132
4132
RETURN_COPY_DEREF (prop );
4133
4133
}
4134
4134
4135
4135
if (def_value ) {
4136
4136
RETURN_COPY (def_value );
4137
4137
}
4138
4138
4139
- zend_throw_exception_ex (reflection_exception_ptr , 0 ,
4140
- "Property %s::$%s does not exist" , ZSTR_VAL (ce -> name ), ZSTR_VAL (name ));
4139
+ if (prop ) {
4140
+ zend_throw_error (NULL ,
4141
+ "Typed property %s::$%s must not be accessed before initialization" , ZSTR_VAL (ce -> name ), ZSTR_VAL (name ));
4142
+ } else {
4143
+ zend_throw_exception_ex (reflection_exception_ptr , 0 ,
4144
+ "Property %s::$%s does not exist" , ZSTR_VAL (ce -> name ), ZSTR_VAL (name ));
4145
+ }
4141
4146
}
4142
4147
/* }}} */
4143
4148
Original file line number Diff line number Diff line change
1
+ --TEST--
2
+ GH-12856 (ReflectionClass::getStaticPropertyValue() returns UNDEF zval for uninitialized typed properties)
3
+ --FILE--
4
+ <?php
5
+
6
+ class Bug {
7
+ private static $ untyped ;
8
+ private static int $ typed1 ;
9
+ private static int $ typed2 = 3 ;
10
+ }
11
+
12
+ $ rc = new ReflectionClass (Bug::class);
13
+ var_dump ($ rc ->getStaticPropertyValue ('untyped ' ));
14
+ try {
15
+ var_dump ($ rc ->getStaticPropertyValue ('typed1 ' ));
16
+ } catch (Error $ e ) {
17
+ echo $ e ->getMessage (), "\n" ;
18
+ }
19
+ var_dump ($ rc ->getStaticPropertyValue ('typed1 ' , 1 ));
20
+ var_dump ($ rc ->getStaticPropertyValue ('typed2 ' ));
21
+
22
+ ?>
23
+ --EXPECT--
24
+ NULL
25
+ Typed property Bug::$typed1 must not be accessed before initialization
26
+ int(1)
27
+ int(3)
You can’t perform that action at this time.
0 commit comments