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