1--TEST--
2ReflectionGenerator basic test
3--FILE--
4<?php
5
6function foo() {
7    yield;
8}
9
10$gens = [
11    (new class() {
12        function a() {
13            yield from foo();
14        }
15    })->a(),
16    (function() {
17        yield;
18    })(),
19    foo(),
20];
21
22foreach ($gens as $gen) {
23    var_dump($gen);
24
25    $gen->valid(); // start Generator
26    $ref = new ReflectionGenerator($gen);
27
28    var_dump($ref->getTrace());
29    var_dump($ref->getExecutingLine());
30    var_dump($ref->getExecutingFile());
31    var_dump($ref->getExecutingGenerator());
32    var_dump($ref->getFunction());
33    var_dump($ref->getThis());
34}
35
36?>
37--EXPECTF--
38object(Generator)#%d (1) {
39  ["function"]=>
40  string(%d) "class@anonymous%s::a"
41}
42array(2) {
43  [0]=>
44  array(4) {
45    ["file"]=>
46    string(%d) "%s"
47    ["line"]=>
48    int(%d)
49    ["function"]=>
50    string(3) "foo"
51    ["args"]=>
52    array(0) {
53    }
54  }
55  [1]=>
56  array(5) {
57    ["function"]=>
58    string(1) "a"
59    ["class"]=>
60    string(%d) "class@anonymous%s"
61    ["object"]=>
62    object(class@anonymous)#%d (0) {
63    }
64    ["type"]=>
65    string(2) "->"
66    ["args"]=>
67    array(0) {
68    }
69  }
70}
71int(%d)
72string(%d) "%sReflectionGenerator_basic.%s"
73object(Generator)#%d (1) {
74  ["function"]=>
75  string(3) "foo"
76}
77object(ReflectionMethod)#8 (2) {
78  ["name"]=>
79  string(1) "a"
80  ["class"]=>
81  string(%d) "class@anonymous%s"
82}
83object(class@anonymous)#1 (0) {
84}
85object(Generator)#%d (1) {
86  ["function"]=>
87  string(%d) "{closure:%s:%d}"
88}
89array(1) {
90  [0]=>
91  array(2) {
92    ["function"]=>
93    string(%d) "{closure:%s:%d}"
94    ["args"]=>
95    array(0) {
96    }
97  }
98}
99int(%d)
100string(%d) "%sReflectionGenerator_basic.%s"
101object(Generator)#%d (1) {
102  ["function"]=>
103  string(%d) "{closure:%s:%d}"
104}
105object(ReflectionFunction)#7 (1) {
106  ["name"]=>
107  string(%d) "{closure:%s:%d}"
108}
109NULL
110object(Generator)#%d (1) {
111  ["function"]=>
112  string(3) "foo"
113}
114array(1) {
115  [0]=>
116  array(2) {
117    ["function"]=>
118    string(3) "foo"
119    ["args"]=>
120    array(0) {
121    }
122  }
123}
124int(%d)
125string(%d) "%sReflectionGenerator_basic.%s"
126object(Generator)#%d (1) {
127  ["function"]=>
128  string(3) "foo"
129}
130object(ReflectionFunction)#8 (1) {
131  ["name"]=>
132  string(3) "foo"
133}
134NULL
135