diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a5562f165f76e..91943f59ff632 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -7809,6 +7809,26 @@ ZEND_METHOD(ReflectionConstant, getShortName) } } +ZEND_METHOD(ReflectionConstant, getType) +{ + reflection_object *intern; + zend_constant *const_; + + if (zend_parse_parameters_none() == FAILURE) { + RETURN_THROWS(); + } + + GET_REFLECTION_OBJECT_PTR(const_); + + zend_type fake_type; + if (Z_TYPE(const_->value) == IS_OBJECT) { + fake_type = (zend_type) ZEND_TYPE_INIT_CLASS(Z_OBJCE(const_->value)->name, false, 0); + } else { + fake_type = (zend_type) ZEND_TYPE_INIT_CODE(Z_TYPE(const_->value), false, 0); + } + reflection_type_factory(fake_type, return_value, 1); +} + ZEND_METHOD(ReflectionConstant, getValue) { reflection_object *intern; diff --git a/ext/reflection/php_reflection.stub.php b/ext/reflection/php_reflection.stub.php index d9acc08d22424..c141bf9528205 100644 --- a/ext/reflection/php_reflection.stub.php +++ b/ext/reflection/php_reflection.stub.php @@ -910,6 +910,8 @@ public function getNamespaceName(): string {} public function getShortName(): string {} + public function getType(): ?ReflectionType {} + public function getValue(): mixed {} public function isDeprecated(): bool {} diff --git a/ext/reflection/php_reflection_arginfo.h b/ext/reflection/php_reflection_arginfo.h index 92d80de5a60ca..3934a58016dde 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: 1cdf310b94e2297a4e426bd4c0c1ab4d5995936d */ + * Stub hash: 314126459d3ab14f4f4ddfc83c1363f53436df30 */ ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 1, IS_ARRAY, 0) ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0) @@ -698,6 +698,8 @@ ZEND_END_ARG_INFO() #define arginfo_class_ReflectionConstant_getShortName arginfo_class_ReflectionFunction___toString +#define arginfo_class_ReflectionConstant_getType arginfo_class_ReflectionFunctionAbstract_getTentativeReturnType + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionConstant_getValue, 0, 0, IS_MIXED, 0) ZEND_END_ARG_INFO() @@ -966,6 +968,7 @@ ZEND_METHOD(ReflectionConstant, __construct); ZEND_METHOD(ReflectionConstant, getName); ZEND_METHOD(ReflectionConstant, getNamespaceName); ZEND_METHOD(ReflectionConstant, getShortName); +ZEND_METHOD(ReflectionConstant, getType); ZEND_METHOD(ReflectionConstant, getValue); ZEND_METHOD(ReflectionConstant, isDeprecated); ZEND_METHOD(ReflectionConstant, __toString); @@ -1330,6 +1333,7 @@ static const zend_function_entry class_ReflectionConstant_methods[] = { ZEND_ME(ReflectionConstant, getName, arginfo_class_ReflectionConstant_getName, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionConstant, getNamespaceName, arginfo_class_ReflectionConstant_getNamespaceName, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionConstant, getShortName, arginfo_class_ReflectionConstant_getShortName, ZEND_ACC_PUBLIC) + ZEND_ME(ReflectionConstant, getType, arginfo_class_ReflectionConstant_getType, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionConstant, getValue, arginfo_class_ReflectionConstant_getValue, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionConstant, isDeprecated, arginfo_class_ReflectionConstant_isDeprecated, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionConstant, __toString, arginfo_class_ReflectionConstant___toString, ZEND_ACC_PUBLIC) diff --git a/ext/reflection/tests/ReflectionConstant_getType.phpt b/ext/reflection/tests/ReflectionConstant_getType.phpt new file mode 100644 index 0000000000000..80b0570f9d55a --- /dev/null +++ b/ext/reflection/tests/ReflectionConstant_getType.phpt @@ -0,0 +1,40 @@ +--TEST-- +ReflectionConstant::getType() +--FILE-- +getType(), "\n"; +} + +?> +--EXPECT-- +stdClass +null +true +string +array +int +float +stdClass