[php-src] Issue #8486: Add a hasPrototype method to ReflectionMethod

From: Date: Tue, 03 May 2022 11:30:40 +0000
Subject: [php-src] Issue #8486: Add a hasPrototype method to ReflectionMethod
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241396@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8486 Author: ollieread ### Description There currently exists a method, ReflectionMethod::getPrototype() to get a methods prototype. This method will throw an exception if one does not exist, but it provides no way to check if a method has a prototype. Most other methods within the reflection extension that throw an exception for a get method also have a corresponding has method. Without a hasPrototype method, developers need to use the exception to control application flow, which is an undesirable approach. If my albeit limited understanding of the source is correct, the following within ext/reflection/php_reflection.c will achieve this. ```c ZEND_METHOD(ReflectionMethod, hasPrototype) { reflection_object *intern; zend_function *mptr; GET_REFLECTION_OBJECT_PTR(mptr); if (zend_parse_parameters_none() == FAILURE) { RETURN_THROWS(); } RETURN_BOOL(mptr->common.prototype != null); } ``` I believe the following would also need to be done. ## Update the stub ext/reflection/php_reflection.stub.php ```php /** @tentative-return-type */ public function hasPrototype(): bool {} ``` ## Update the arginfo ext/reflection/php_reflection_arginfo.h ```h ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_ReflectionMethod_hasPrototype, 0, 0, _IS_BOOL, 0) ZEND_END_ARG_INFO() //... ZEND_METHOD(ReflectionMethod, hasPrototype); //... ZEND_ME(ReflectionMethod, hasPrototype, arginfo_class_ReflectionMethod_hasPrototype, ZEND_ACC_PUBLIC) ```

« previous php.bugs (#241396) next »