diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 2d20bd07a68..4b05a4d0ac5 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -192,16 +192,6 @@ static inline bool is_closure_invoke(zend_class_entry *ce, zend_string *lcname) && zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME); } -static void _default_get_name(zval *object, zval *return_value) /* {{{ */ -{ - zval *name = reflection_prop_name(object); - if (Z_ISUNDEF_P(name)) { - RETURN_FALSE; - } - ZVAL_COPY(return_value, name); -} -/* }}} */ - static zend_function *_copy_function(zend_function *fptr) /* {{{ */ { if (fptr @@ -3634,15 +3624,24 @@ ZEND_METHOD(ReflectionClassConstant, __toString) reflection_object *intern; zend_class_constant *ref; smart_str str = {0}; - zval name; if (zend_parse_parameters_none() == FAILURE) { RETURN_THROWS(); } + GET_REFLECTION_OBJECT_PTR(ref); - _default_get_name(ZEND_THIS, &name); - _class_const_string(&str, Z_STRVAL(name), ref, ""); - zval_ptr_dtor(&name); + + zval *name = reflection_prop_name(ZEND_THIS); + if (Z_ISUNDEF_P(name)) { + zend_throw_error(NULL, + "Typed property ReflectionClassConstant::$name " + "must not be accessed before initialization"); + RETURN_THROWS(); + } + ZVAL_DEREF(name); + ZEND_ASSERT(Z_TYPE_P(name) == IS_STRING); + + _class_const_string(&str, Z_STRVAL_P(name), ref, ""); RETURN_STR(smart_str_extract(&str)); } /* }}} */ @@ -3653,7 +3652,16 @@ ZEND_METHOD(ReflectionClassConstant, getName) if (zend_parse_parameters_none() == FAILURE) { RETURN_THROWS(); } - _default_get_name(ZEND_THIS, return_value); + + zval *name = reflection_prop_name(ZEND_THIS); + if (Z_ISUNDEF_P(name)) { + zend_throw_error(NULL, + "Typed property ReflectionClassConstant::$name " + "must not be accessed before initialization"); + RETURN_THROWS(); + } + + ZVAL_COPY_DEREF(return_value, name); } /* }}} */ diff --git a/ext/reflection/php_reflection.stub.php b/ext/reflection/php_reflection.stub.php index fe8def14b72..69384f88bb3 100644 --- a/ext/reflection/php_reflection.stub.php +++ b/ext/reflection/php_reflection.stub.php @@ -455,7 +455,7 @@ class ReflectionClassConstant implements Reflector public function __toString(): string {} - /** @return string|false */ + /** @return string */ public function getName() {} /** @return mixed */ diff --git a/ext/reflection/php_reflection_arginfo.h b/ext/reflection/php_reflection_arginfo.h index a6d6bfdd726..b1ea070d2ac 100644 --- a/ext/reflection/php_reflection_arginfo.h +++ b/ext/reflection/php_reflection_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 388312e928b54992da6b7e0e0f15dec72d9290f1 */ + * Stub hash: 47ac64b027cdeb0e9996147277f79fa9d6b876bd */ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)