Skip to content

Commit ad0da9a

Browse files
committed
Implemented ReflectionFunction::isGenerator()
1 parent e212de4 commit ad0da9a

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

ext/reflection/php_reflection.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,6 +3086,14 @@ ZEND_METHOD(reflection_function, isDeprecated)
30863086
}
30873087
/* }}} */
30883088

3089+
/* {{{ proto public bool ReflectionFunction::isGenerator()
3090+
Returns whether this function is a generator */
3091+
ZEND_METHOD(reflection_function, isGenerator)
3092+
{
3093+
_function_check_flag(INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_ACC_GENERATOR);
3094+
}
3095+
/* }}} */
3096+
30893097
/* {{{ proto public bool ReflectionFunction::inNamespace()
30903098
Returns whether this function is defined in namespace */
30913099
ZEND_METHOD(reflection_function, inNamespace)
@@ -5696,6 +5704,7 @@ static const zend_function_entry reflection_function_abstract_functions[] = {
56965704
ZEND_ME(reflection_function, isDeprecated, arginfo_reflection__void, 0)
56975705
ZEND_ME(reflection_function, isInternal, arginfo_reflection__void, 0)
56985706
ZEND_ME(reflection_function, isUserDefined, arginfo_reflection__void, 0)
5707+
ZEND_ME(reflection_function, isGenerator, arginfo_reflection__void, 0)
56995708
ZEND_ME(reflection_function, getClosureThis, arginfo_reflection__void, 0)
57005709
ZEND_ME(reflection_function, getClosureScopeClass, arginfo_reflection__void, 0)
57015710
ZEND_ME(reflection_function, getDocComment, arginfo_reflection__void, 0)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
--TEST--
2+
ReflectionFunction::isGenerator()
3+
--FILE--
4+
<?php
5+
6+
$closure1 = function() {return "this is a closure"; };
7+
$closure2 = function($param) {
8+
yield $param;
9+
};
10+
11+
$rf1 = new ReflectionFunction($closure1);
12+
var_dump($rf1->isGenerator());
13+
14+
$rf2 = new ReflectionFunction($closure2);
15+
var_dump($rf2->isGenerator());
16+
17+
function func1() {
18+
return 'func1';
19+
}
20+
21+
function func2() {
22+
yield 'func2';
23+
}
24+
25+
$rf1 = new ReflectionFunction('func1');
26+
var_dump($rf1->isGenerator());
27+
28+
$rf2 = new ReflectionFunction('func2');
29+
var_dump($rf2->isGenerator());
30+
31+
32+
class Foo {
33+
public function f1() {
34+
}
35+
36+
public function f2() {
37+
yield;
38+
}
39+
}
40+
41+
$rc = new ReflectionClass('Foo');
42+
foreach($rc->getMethods() as $m) {
43+
var_dump($m->isGenerator());
44+
}
45+
?>
46+
--EXPECTF--
47+
bool(false)
48+
bool(true)
49+
bool(false)
50+
bool(true)
51+
bool(false)
52+
bool(true)

0 commit comments

Comments
 (0)