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:
2
NEWS
2
NEWS
@@ -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
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
27
ext/reflection/tests/gh12856.phpt
Normal file
27
ext/reflection/tests/gh12856.phpt
Normal 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)
|
||||
Reference in New Issue
Block a user