1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

Add ReflectionMethod::hasPrototype method

Closes GH-8487.
This commit is contained in:
Ollie Read
2022-05-04 13:21:37 +02:00
committed by Christoph M. Becker
parent 6db78f3ed9
commit f590782b60
6 changed files with 58 additions and 1 deletions

1
NEWS
View File

@@ -36,6 +36,7 @@ PHP NEWS
- Reflection:
. Added ReflectionFunction::isAnonymous(). (Nicolas Grekas)
. Added ReflectionMethod::hasPrototype(). (Ollie Read)
- Sodium:
. Added sodium_crypto_stream_xchacha20_xor_ic(). (Scott)

View File

@@ -140,6 +140,7 @@ PHP 8.2 UPGRADE NOTES
- Reflection:
. ReflectionFunction::isAnonymous()
. ReflectionMethod::hasPrototype()
- Sodium:
. sodium_crypto_stream_xchacha20_xor_ic()

View File

@@ -3667,6 +3667,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)
{

View File

@@ -206,6 +206,8 @@ class ReflectionMethod extends ReflectionFunctionAbstract
/** @tentative-return-type */
public function getPrototype(): ReflectionMethod {}
public function hasPrototype(): bool {}
/** @tentative-return-type */
public function setAccessible(bool $accessible): void {}
}

View File

@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: f06163b02a76ee7fa526e4662f015201e243743d */
* Stub hash: c9656b23db965e890e73d0064005b981ee1991cf */
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)
@@ -169,6 +169,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()
@@ -659,6 +661,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);
@@ -918,6 +921,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
};

View File

@@ -0,0 +1,34 @@
--TEST--
public ReflectionMethod ReflectionMethod::hasPrototype ( void );
--FILE--
<?php
class Hello {
public function sayHelloTo($name) {
return 'Hello ' . $name;
}
}
class HelloWorld extends Hello {
public function sayHelloTo($name) {
return 'Hello world: ' . $name;
}
public function sayHiTo($name) {
return 'Hi: ' . $name;
}
}
$reflectionMethod1 = new ReflectionMethod('HelloWorld', 'sayHelloTo');
var_dump($reflectionMethod1->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)