diff --git a/NEWS b/NEWS index a6555ac871c9..9bdc0737be9b 100644 --- a/NEWS +++ b/NEWS @@ -369,6 +369,8 @@ PHP NEWS - Reflection: . Fix trampoline leak when object construction fails for lazy object. (ndossche) + . Fixed ReflectionClassConstant::getValue() reading a reference as the name + of the constant in the error raised for a typed constant. (Nicolas Grekas) - SAPI: . Fixed infinite loop in sapi_header_op() for headers of 4 GiB or more. diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index c0a8b11e0cf7..18ab71b63604 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4143,6 +4143,9 @@ ZEND_METHOD(ReflectionClassConstant, getValue) RETURN_THROWS(); } + ZVAL_DEREF(name); + ZEND_ASSERT(Z_TYPE_P(name) == IS_STRING); + if (Z_TYPE(ref->value) == IS_CONSTANT_AST) { zend_result result = zend_update_class_constant(ref, Z_STR_P(name), ref->ce); if (result == FAILURE) { diff --git a/ext/reflection/tests/ReflectionClassConstant_getValue_name_reference.phpt b/ext/reflection/tests/ReflectionClassConstant_getValue_name_reference.phpt new file mode 100644 index 000000000000..b9dc70ef75be --- /dev/null +++ b/ext/reflection/tests/ReflectionClassConstant_getValue_name_reference.phpt @@ -0,0 +1,22 @@ +--TEST-- +ReflectionClassConstant::getValue() after taking a reference to the name property +--FILE-- +name; +try { + var_dump($rc->getValue()); +} catch (Throwable $e) { + echo $e::class, ": ", $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +TypeError: Cannot assign string to class constant Test::C of type int