@@ -76,7 +76,18 @@ public static function castClosure(\Closure $c, array $a, Stub $stub, $isNested)
76
76
77
77
public static function castGenerator (\Generator $ c , array $ a , Stub $ stub , $ isNested )
78
78
{
79
- return class_exists ('ReflectionGenerator ' , false ) ? self ::castReflectionGenerator (new \ReflectionGenerator ($ c ), $ a , $ stub , $ isNested ) : $ a ;
79
+ if (!class_exists ('ReflectionGenerator ' , false )) {
80
+ return $ a ;
81
+ }
8000
code>
82
+
83
+ // Cannot create ReflectionGenerator based on a terminated Generator
84
+ try {
85
+ $ reflectionGenerator = new \ReflectionGenerator ($ c );
86
+ } catch (\Exception $ e ) {
87
+ return $ a ;
88
+ }
89
+
90
+ return self ::castReflectionGenerator ($ reflectionGenerator , $ a , $ stub , $ isNested );
80
91
}
81
92
82
93
public static function castType (\ReflectionType $ c , array $ a , Stub $ stub , $ isNested )
@@ -99,28 +110,28 @@ public static function castReflectionGenerator(\ReflectionGenerator $c, array $a
99
110
if ($ c ->getThis ()) {
100
111
$ a [$ prefix .'this ' ] = new CutStub ($ c ->getThis ());
101
112
}
102
- $ x = $ c ->getFunction ();
113
+ $ function = $ c ->getFunction ();
103
114
$ frame = array (
104
- 'class ' => isset ($ x ->class ) ? $ x ->class : null ,
105
- 'type ' => isset ($ x ->class ) ? ($ x ->isStatic () ? ':: ' : '-> ' ) : null ,
106
- 'function ' => $ x ->name ,
115
+ 'class ' => isset ($ function ->class ) ? $ function ->class : null ,
116
+ 'type ' => isset ($ function ->class ) ? ($ function ->isStatic () ? ':: ' : '-> ' ) : null ,
117
+ 'function ' => $ function ->name ,
107
118
'file ' => $ c ->getExecutingFile (),
108
119
'line ' => $ c ->getExecutingLine (),
109
120
);
110
121
if ($ trace = $ c ->getTrace (DEBUG_BACKTRACE_IGNORE_ARGS )) {
111
- $ x = new \ReflectionGenerator ($ c ->getExecutingGenerator ());
122
+ $ function = new \ReflectionGenerator ($ c ->getExecutingGenerator ());
112
123
array_unshift ($ trace , array (
113
124
'function ' => 'yield ' ,
114
- 'file ' => $ x ->getExecutingFile (),
115
- 'line ' => $ x ->getExecutingLine () - 1 ,
125
+ 'file ' => $ function ->getExecutingFile (),
126
+ 'line ' => $ function ->getExecutingLine () - 1 ,
116
127
));
117
128
$ trace [] = $ frame ;
118
129
$ a [$ prefix .'trace ' ] = new TraceStub ($ trace , false , 0 , -1 , -1 );
119
130
} else {
120
- $ x = new FrameStub ($ frame , false , true );
121
- $ x = ExceptionCaster::castFrameStub ($ x , array (), $ x , true );
131
+ $ function = new FrameStub ($ frame , false , true );
132
+ $ function = ExceptionCaster::castFrameStub ($ function , array (), $ function , true );
122
133
$ a [$ prefix .'executing ' ] = new EnumStub (array (
123
- $ frame ['class ' ].$ frame ['type ' ].$ frame ['function ' ].'() ' => $ x [$ prefix .'src ' ],
134
+ $ frame ['class ' ].$ frame ['type ' ].$ frame ['function ' ].'() ' => $ function [$ prefix .'src ' ],
124
135
));
125
136
}
126
137
0 commit comments