@@ -316,6 +316,7 @@ static bool zend_is_not_imported(zend_string *name) {
316
316
void zend_oparray_context_begin (zend_oparray_context * prev_context ) /* {{{ */
317
317
{
318
318
* prev_context = CG (context );
319
+ CG (context ).prev = CG (context ).op_array ? prev_context : NULL ;
319
320
CG (context ).opcodes_size = INITIAL_OP_ARRAY_SIZE ;
320
321
CG (context ).vars_size = 0 ;
321
322
CG (context ).literals_size = 0 ;
@@ -2920,11 +2921,21 @@ static bool is_global_var_fetch(zend_ast *ast)
2920
2921
2921
2922
static bool this_guaranteed_exists (void ) /* {{{ */
2922
2923
{
2923
- zend_op_array * op_array = CG (active_op_array );
2924
- /* Instance methods always have a $this.
2925
- * This also includes closures that have a scope and use $this. */
2926
- return op_array -> scope != NULL
2927
- && (op_array -> fn_flags & ZEND_ACC_STATIC ) == 0 ;
2924
+ zend_oparray_context * ctx = & CG (context );
2925
+ while (ctx ) {
2926
+ /* Instance methods always have a $this.
2927
+ * This also includes closures that have a scope and use $this. */
2928
+ zend_op_array * op_array = ctx -> op_array ;
2929
+ if (op_array -> fn_flags & ZEND_ACC_STATIC ) {
2930
+ return false;
2931
+ } else if (op_array -> scope ) {
2932
+ return true;
2933
+ } else if (!(op_array -> fn_flags & ZEND_ACC_CLOSURE )) {
2934
+ return false;
2935
+ }
2936
+ ctx = ctx -> prev ;
2937
+ }
2938
+ return false;
2928
2939
}
2929
2940
/* }}} */
2930
2941
@@ -7870,6 +7881,7 @@ static void zend_compile_func_decl(znode *result, zend_ast *ast, bool toplevel)
7870
7881
}
7871
7882
7872
7883
zend_oparray_context_begin (& orig_oparray_context );
7884
+ CG (context ).op_array = op_array ;
7873
7885
7874
7886
{
7875
7887
/* Push a separator to the loop variable stack */
0 commit comments