1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix GH-12856: ReflectionClass::getStaticPropertyValue() returns UNDEF zval for uninitialized typed properties

Closes GH-17590.
This commit is contained in:
Niels Dossche
2025-01-26 19:26:36 +01:00
parent efca8cb682
commit 6e84c41d05
3 changed files with 37 additions and 3 deletions

2
NEWS
View File

@@ -81,6 +81,8 @@ PHP NEWS
- Reflection:
. Added ReflectionConstant::getExtension() and ::getExtensionName().
(DanielEScherzer)
. Fixed bug GH-12856 (ReflectionClass::getStaticPropertyValue() returns UNDEF
zval for uninitialized typed properties). (nielsdos)
- Session:
. session_start() throws a ValueError on option argument if not a hashmap

View File

@@ -4128,7 +4128,7 @@ ZEND_METHOD(ReflectionClass, getStaticPropertyValue)
prop = zend_std_get_static_property(ce, name, BP_VAR_IS);
EG(fake_scope) = old_scope;
if (prop) {
if (prop && !Z_ISUNDEF_P(prop)) {
RETURN_COPY_DEREF(prop);
}
@@ -4136,8 +4136,13 @@ ZEND_METHOD(ReflectionClass, getStaticPropertyValue)
RETURN_COPY(def_value);
}
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Property %s::$%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name));
if (prop) {
zend_throw_error(NULL,
"Typed property %s::$%s must not be accessed before initialization", ZSTR_VAL(ce->name), ZSTR_VAL(name));
} else {
zend_throw_exception_ex(reflection_exception_ptr, 0,
"Property %s::$%s does not exist", ZSTR_VAL(ce->name), ZSTR_VAL(name));
}
}
/* }}} */

View File

@@ -0,0 +1,27 @@
--TEST--
GH-12856 (ReflectionClass::getStaticPropertyValue() returns UNDEF zval for uninitialized typed properties)
--FILE--
<?php
class Bug {
private static $untyped;
private static int $typed1;
private static int $typed2 = 3;
}
$rc = new ReflectionClass(Bug::class);
var_dump($rc->getStaticPropertyValue('untyped'));
try {
var_dump($rc->getStaticPropertyValue('typed1'));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
var_dump($rc->getStaticPropertyValue('typed1', 1));
var_dump($rc->getStaticPropertyValue('typed2'));
?>
--EXPECT--
NULL
Typed property Bug::$typed1 must not be accessed before initialization
int(1)
int(3)