diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 33ec42c75794e..696e00136ee70 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -3654,6 +3654,21 @@ ZEND_METHOD(ReflectionMethod, getDeclaringClass) } /* }}} */ +/* {{{ Returns whether a method has a prototype or not */ +ZEND_METHOD(ReflectionMethod, hasPrototype) +{ + reflection_object *intern; + zend_function *mptr; + + if (zend_parse_parameters_none() == FAILURE) { + RETURN_THROWS(); + } + + GET_REFLECTION_OBJECT_PTR(mptr); + RETURN_BOOL(mptr->common.prototype != NULL); +} +/* }}} */ + /* {{{ Get the prototype */ ZEND_METHOD(ReflectionMethod, getPrototype) { diff --git a/ext/reflection/php_reflection.stub.php b/ext/reflection/php_reflection.stub.php index 8f2ef6ec6f44e..0307a9e64b477 100644 --- a/ext/reflection/php_reflection.stub.php +++ b/ext/reflection/php_reflection.stub.php @@ -204,6 +204,8 @@ public function getDeclaringClass(): ReflectionClass {} /** @tentative-return-type */ public function getPrototype(): ReflectionMethod {} + public function hasPrototype(): bool {} + /** @tentative-return-type */ public function setAccessible(bool $accessible): void {} } diff --git a/ext/reflection/php_reflection_arginfo.h b/ext/reflection/php_reflection_arginfo.h index 12b01c4d264fd..aa512751b55ce 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: 62fcf63d2f3e93537560c3a03e71fda131a31586 */ + * Stub hash: 7cafe54fd9a94ea020367cd8f9ad090160905716 */ 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) @@ -167,6 +167,8 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_ReflectionMethod_getPrototype, 0, 0, ReflectionMethod, 0) ZEND_END_ARG_INFO() +#define arginfo_class_ReflectionMethod_hasPrototype arginfo_class_ReflectionFunctionAbstract_hasTentativeReturnType + ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionMethod_setAccessible, 0, 1, IS_VOID, 0) ZEND_ARG_TYPE_INFO(0, accessible, _IS_BOOL, 0) ZEND_END_ARG_INFO() @@ -656,6 +658,7 @@ ZEND_METHOD(ReflectionMethod, invoke); ZEND_METHOD(ReflectionMethod, invokeArgs); ZEND_METHOD(ReflectionMethod, getDeclaringClass); ZEND_METHOD(ReflectionMethod, getPrototype); +ZEND_METHOD(ReflectionMethod, hasPrototype); ZEND_METHOD(ReflectionMethod, setAccessible); ZEND_METHOD(ReflectionClass, __construct); ZEND_METHOD(ReflectionClass, __toString); @@ -914,6 +917,7 @@ static const zend_function_entry class_ReflectionMethod_methods[] = { ZEND_ME(ReflectionMethod, invokeArgs, arginfo_class_ReflectionMethod_invokeArgs, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionMethod, getDeclaringClass, arginfo_class_ReflectionMethod_getDeclaringClass, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionMethod, getPrototype, arginfo_class_ReflectionMethod_getPrototype, ZEND_ACC_PUBLIC) + ZEND_ME(ReflectionMethod, hasPrototype, arginfo_class_ReflectionMethod_hasPrototype, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionMethod, setAccessible, arginfo_class_ReflectionMethod_setAccessible, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/ext/reflection/tests/ReflectionMethod_hasPrototype_basic.phpt b/ext/reflection/tests/ReflectionMethod_hasPrototype_basic.phpt new file mode 100644 index 0000000000000..d94c8962e11b3 --- /dev/null +++ b/ext/reflection/tests/ReflectionMethod_hasPrototype_basic.phpt @@ -0,0 +1,34 @@ +--TEST-- +public ReflectionMethod ReflectionMethod::hasPrototype ( void ); +--FILE-- +hasPrototype()); + +$reflectionMethod2 = new ReflectionMethod('Hello', 'sayHelloTo'); +var_dump($reflectionMethod2->hasPrototype()); + +$reflectionMethod3 = new ReflectionMethod('HelloWorld', 'sayHiTo'); +var_dump($reflectionMethod3->hasPrototype()); + +?> +--EXPECT-- +bool(true) +bool(false) +bool(false)