Skip to content

Commit f590782

Browse files
olliereadcmb69
authored andcommitted
Add ReflectionMethod::hasPrototype method
Closes GH-8487.
1 parent 6db78f3 commit f590782

File tree

6 files changed

+58
-1
lines changed

6 files changed

+58
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ PHP NEWS
3636

3737
- Reflection:
3838
. Added ReflectionFunction::isAnonymous(). (Nicolas Grekas)
39+
. Added ReflectionMethod::hasPrototype(). (Ollie Read)
3940

4041
- Sodium:
4142
. Added sodium_crypto_stream_xchacha20_xor_ic(). (Scott)

UPGRADING

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ PHP 8.2 UPGRADE NOTES
140140

141141
- Reflection:
142142
. ReflectionFunction::isAnonymous()
143+
. ReflectionMethod::hasPrototype()
143144

144145
- Sodium:
145146
. sodium_crypto_stream_xchacha20_xor_ic()

ext/reflection/php_reflection.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3667,6 +3667,21 @@ ZEND_METHOD(ReflectionMethod, getDeclaringClass)
36673667
}
36683668
/* }}} */
36693669

3670+
/* {{{ Returns whether a method has a prototype or not */
3671+
ZEND_METHOD(ReflectionMethod, hasPrototype)
3672+
{
3673+
reflection_object *intern;
3674+
zend_function *mptr;
3675+
3676+
if (zend_parse_parameters_none() == FAILURE) {
3677+
RETURN_THROWS();
3678+
}
3679+
3680+
GET_REFLECTION_OBJECT_PTR(mptr);
3681+
RETURN_BOOL(mptr->common.prototype != NULL);
3682+
}
3683+
/* }}} */
3684+
36703685
/* {{{ Get the prototype */
36713686
ZEND_METHOD(ReflectionMethod, getPrototype)
36723687
{

ext/reflection/php_reflection.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public function getDeclaringClass(): ReflectionClass {}
206206
/** @tentative-return-type */
207207
public function getPrototype(): ReflectionMethod {}
208208

209+
public function hasPrototype(): bool {}
210+
209211
/** @tentative-return-type */
210212
public function setAccessible(bool $accessible): void {}
211213
}

ext/reflection/php_reflection_arginfo.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: f06163b02a76ee7fa526e4662f015201e243743d */
2+
* Stub hash: c9656b23db965e890e73d0064005b981ee1991cf */
33

44
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_Reflection_getModifierNames, 0, 1, IS_ARRAY, 0)
55
ZEND_ARG_TYPE_INFO(0, modifiers, IS_LONG, 0)
@@ -169,6 +169,8 @@ ZEND_END_ARG_INFO()
169169
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_OBJ_INFO_EX(arginfo_class_ReflectionMethod_getPrototype, 0, 0, ReflectionMethod, 0)
170170
ZEND_END_ARG_INFO()
171171

172+
#define arginfo_class_ReflectionMethod_hasPrototype arginfo_class_ReflectionFunctionAbstract_hasTentativeReturnType
173+
172174
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_ReflectionMethod_setAccessible, 0, 1, IS_VOID, 0)
173175
ZEND_ARG_TYPE_INFO(0, accessible, _IS_BOOL, 0)
174176
ZEND_END_ARG_INFO()
@@ -659,6 +661,7 @@ ZEND_METHOD(ReflectionMethod, invoke);
659661
ZEND_METHOD(ReflectionMethod, invokeArgs);
660662
ZEND_METHOD(ReflectionMethod, getDeclaringClass);
661663
ZEND_METHOD(ReflectionMethod, getPrototype);
664+
ZEND_METHOD(ReflectionMethod, hasPrototype);
662665
ZEND_METHOD(ReflectionMethod, setAccessible);
663666
ZEND_METHOD(ReflectionClass, __construct);
664667
ZEND_METHOD(ReflectionClass, __toString);
@@ -918,6 +921,7 @@ static const zend_function_entry class_ReflectionMethod_methods[] = {
918921
ZEND_ME(ReflectionMethod, invokeArgs, arginfo_class_ReflectionMethod_invokeArgs, ZEND_ACC_PUBLIC)
919922
ZEND_ME(ReflectionMethod, getDeclaringClass, arginfo_class_ReflectionMethod_getDeclaringClass, ZEND_ACC_PUBLIC)
920923
ZEND_ME(ReflectionMethod, getPrototype, arginfo_class_ReflectionMethod_getPrototype, ZEND_ACC_PUBLIC)
924+
ZEND_ME(ReflectionMethod, hasPrototype, arginfo_class_ReflectionMethod_hasPrototype, ZEND_ACC_PUBLIC)
921925
ZEND_ME(ReflectionMethod, setAccessible, arginfo_class_ReflectionMethod_setAccessible, ZEND_ACC_PUBLIC)
922926
ZEND_FE_END
923927
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
public ReflectionMethod ReflectionMethod::hasPrototype ( void );
3+
--FILE--
4+
<?php
5+
class Hello {
6+
public function sayHelloTo($name) {
7+
return 'Hello ' . $name;
8+
}
9+
}
10+
11+
class HelloWorld extends Hello {
12+
public function sayHelloTo($name) {
13+
return 'Hello world: ' . $name;
14+
}
15+
16+
public function sayHiTo($name) {
17+
return 'Hi: ' . $name;
18+
}
19+
}
20+
21+
$reflectionMethod1 = new ReflectionMethod('HelloWorld', 'sayHelloTo');
22+
var_dump($reflectionMethod1->hasPrototype());
23+
24+
$reflectionMethod2 = new ReflectionMethod('Hello', 'sayHelloTo');
25+
var_dump($reflectionMethod2->hasPrototype());
26+
27+
$reflectionMethod3 = new ReflectionMethod('HelloWorld', 'sayHiTo');
28+
var_dump($reflectionMethod3->hasPrototype());
29+
30+
?>
31+
--EXPECT--
32+
bool(true)
33+
bool(false)
34+
bool(false)

0 commit comments

Comments
 (0)