Skip to content

Commit 535aaa6

Browse files
committed
add ReflectionFunctionAbstract::hasReturnHint
1 parent 507e38f commit 535aaa6

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

ext/reflection/php_reflection.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,6 +1851,21 @@ ZEND_METHOD(reflection_function, getEndLine)
18511851
}
18521852
/* }}} */
18531853

1854+
/* {{{ proto public bool ReflectionFunction::hasReturnHint()
1855+
Checks for the presence of a return hint */
1856+
ZEND_METHOD(reflection_function, hasReturnHint)
1857+
{
1858+
reflection_object *intern;
1859+
zend_function *fptr;
1860+
1861+
if (zend_parse_parameters_none() == FAILURE) {
1862+
return;
1863+
}
1864+
GET_REFLECTION_OBJECT_PTR(fptr);
1865+
RETURN_BOOL(fptr->common.return_hint.used);
1866+
}
1867+
/* }}} */
1868+
18541869
/* {{{ proto public string ReflectionFunction::getDocComment()
18551870
Returns the doc comment for this function */
18561871
ZEND_METHOD(reflection_function, getDocComment)
@@ -5735,6 +5750,7 @@ static const zend_function_entry reflection_function_abstract_functions[] = {
57355750
ZEND_ME(reflection_function, isVariadic, arginfo_reflection__void, 0)
57365751
ZEND_ME(reflection_function, getClosureThis, arginfo_reflection__void, 0)
57375752
ZEND_ME(reflection_function, getClosureScopeClass, arginfo_reflection__void, 0)
5753+
ZEND_ME(reflection_function, hasReturnHint, arginfo_reflection__void, 0)
57385754
ZEND_ME(reflection_function, getDocComment, arginfo_reflection__void, 0)
57395755
ZEND_ME(reflection_function, getEndLine, arginfo_reflection__void, 0)
57405756
ZEND_ME(reflection_function, getExtension, arginfo_reflection__void, 0)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Reflection::hasReturnHint()
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('reflection') || !defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50399) {
6+
print 'skip';
7+
}
8+
?>
9+
--FILE--
10+
<?php
11+
class foo {}
12+
13+
$closure = function($param) : foo { return new foo(); };
14+
$rf = new ReflectionFunction($closure);
15+
var_dump($rf->hasReturnHint());
16+
$closure = function($param) { return new foo(); };
17+
$rf = new ReflectionFunction($closure);
18+
var_dump($rf->hasReturnHint());
19+
--EXPECT--
20+
bool(true)
21+
bool(false)

0 commit comments

Comments
 (0)