]> granicus.if.org Git - php/commitdiff
Fixed bug #31177 (menory leaks and corruption because of incorrect refcounting)
authorDmitry Stogov <dmitry@php.net>
Thu, 20 Oct 2005 07:23:58 +0000 (07:23 +0000)
committerDmitry Stogov <dmitry@php.net>
Thu, 20 Oct 2005 07:23:58 +0000 (07:23 +0000)
Zend/tests/bug31177-2.phpt [new file with mode: 0755]
Zend/zend_compile.h
Zend/zend_extensions.h
Zend/zend_ptr_stack.h
Zend/zend_vm_def.h
Zend/zend_vm_execute.h

diff --git a/Zend/tests/bug31177-2.phpt b/Zend/tests/bug31177-2.phpt
new file mode 100755 (executable)
index 0000000..7afeb73
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #31177 (menory corruption because of incorrect refcounting)
+--FILE--
+<?php
+class foo {
+  function foo($n=0) {
+    if($n) throw new Exception("new");
+  }
+}
+$x = new foo();
+try {
+  $y=$x->foo(1);
+} catch (Exception $e) {
+  var_dump($x);
+}
+--EXPECT--
+object(foo)#1 (0) {
+}
index a8d56e917bc10478c7233fcfb12b4ff9dc5f58d9..c6deb4ab5a6d29053815d64e24efbcbce3aa25fe 100644 (file)
@@ -296,7 +296,6 @@ struct _zend_execute_data {
        union _temp_variable *Ts;
        zval ***CVs;
        zend_bool original_in_execution;
-       zend_class_entry *calling_scope;
        HashTable *symbol_table;
        struct _zend_execute_data *prev_execute_data;
        zval *old_error_reporting;
index 24ea843d8c6f4b44580e85a550fd1e6eda3810df..fbe9eee165a1032215e3794684c5af0818f252ab 100644 (file)
@@ -27,7 +27,7 @@
 /* The first number is the engine version and the rest is the date.
  * This way engine 2 API no. is always greater than engine 1 API no..
  */
-#define ZEND_EXTENSION_API_NO  220050809
+#define ZEND_EXTENSION_API_NO  220050920
 
 typedef struct _zend_extension_version_info {
        int zend_extension_api_no;
index 19436036335b73a3b12ad9b2c46fcdb2b8edd81c..4e13f52374a8c16fbf60703ee4fd4fa548469e63 100644 (file)
@@ -84,7 +84,14 @@ static inline void zend_ptr_stack_3_pop(zend_ptr_stack *stack, void **a, void **
        *a = *(--stack->top_element);
        *b = *(--stack->top_element);
        *c = *(--stack->top_element);
-       stack->top -= 3;;       
+       stack->top -= 3;
+}
+
+static inline void zend_ptr_stack_2_pop(zend_ptr_stack *stack, void **a, void **b)
+{
+       *a = *(--stack->top_element);
+       *b = *(--stack->top_element);
+       stack->top -= 2;
 }
 
 static inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr)
index f9f70ce06e516f875b1b81a4af6df6662bfb5694..09e3d159a8cdae7b43a6e574dec4f09c11f496c1 100644 (file)
@@ -889,11 +889,11 @@ ZEND_VM_HANDLER(40, ZEND_ECHO, CONST|TMP|VAR|CV, ANY)
        /* Convert inline HTML blocks to the output encoding, but only if necessary. */
        if (opline->extended_value &&
                strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status),
-                          EG(active_op_array)->script_encoding)) {
+                          EX(op_array)->script_encoding)) {
                zval z_conv;
                UConverter *script_enc_conv = NULL;
-               if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) {
-                       zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding);
+               if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) {
+                       zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding);
                }
                zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status);
                z_conv.type = IS_BINARY;
@@ -1663,7 +1663,7 @@ ZEND_VM_HANDLER(112, ZEND_INIT_METHOD_CALL, TMP|VAR|UNUSED|CV, CONST|TMP|VAR|CV)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = GET_OP2_ZVAL_PTR(BP_VAR_R);
 
@@ -1674,8 +1674,6 @@ ZEND_VM_HANDLER(112, ZEND_INIT_METHOD_CALL, TMP|VAR|UNUSED|CV, CONST|TMP|VAR|CV)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = GET_OP1_OBJ_ZVAL_PTR(BP_VAR_R);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -1706,12 +1704,6 @@ ZEND_VM_HANDLER(112, ZEND_INIT_METHOD_CALL, TMP|VAR|UNUSED|CV, CONST|TMP|VAR|CV)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        FREE_OP2();
        FREE_OP1_IF_VAR();
 
@@ -1724,7 +1716,7 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, ANY, CONST|TMP|VAR|UNUSED|CV)
        zval *function_name;
        zend_class_entry *ce;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        ce = EX_T(opline->op1.u.var).class_entry;
        if(OP2_TYPE != IS_UNUSED) {
@@ -1758,8 +1750,6 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, ANY, CONST|TMP|VAR|UNUSED|CV)
                EX(fbc) = ce->constructor;
        }
 
-       EX(calling_scope) = EX(fbc)->common.scope;
-
        if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) {
                EX(object) = NULL;
        } else {
@@ -1780,7 +1770,7 @@ ZEND_VM_HANDLER(59, ZEND_INIT_FCALL_BY_NAME, ANY, CONST|TMP|VAR|CV)
        unsigned int function_name_strlen, lcname_len;
        zend_free_op free_op2;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        if (OP2_TYPE == IS_CONST) {
                function_name = &opline->op2.u.constant;
@@ -1805,7 +1795,6 @@ ZEND_VM_HANDLER(59, ZEND_INIT_FCALL_BY_NAME, ANY, CONST|TMP|VAR|CV)
                FREE_OP2();
        }
 
-       EX(calling_scope) = function->common.scope;
        EX(object) = NULL;
 
        EX(fbc) = function;
@@ -1822,6 +1811,7 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY)
        zval *current_this;
        int return_value_used = RETURN_VALUE_USED(opline);
        zend_bool should_change_scope;
+       zend_op *ctor_opline;
 
        if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) {
                /* FIXME: output identifiers properly */
@@ -1839,7 +1829,7 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY)
                current_this = EG(This);
                EG(This) = EX(object);
                current_scope = EG(scope);
-               EG(scope) = EX(calling_scope);
+               EG(scope) = (EX(function_state).function->type == ZEND_USER_FUNCTION || !EX(object)) ? EX(function_state).function->common.scope : NULL;
        } else {
                should_change_scope = 0;
        }
@@ -1968,16 +1958,18 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY)
                }
        }
 
+       ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack));
+
        if (EG(This)) {
-               if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) {
-                       EG(This)->refcount--;
+               if (EG(exception) && ctor_opline) {
+                       if (RETURN_VALUE_USED(ctor_opline)) {
+                               EG(This)->refcount--;
+                       }
                        if (EG(This)->refcount == 1) {
                                zend_object_store_ctor_failed(EG(This) TSRMLS_CC);
                        }
-                       if (should_change_scope && EG(This) != current_this) {
-                               zval_ptr_dtor(&EG(This));
-                       }
-               } else if (should_change_scope) {
+               }
+               if (should_change_scope) {
                        zval_ptr_dtor(&EG(This));
                }
        }
@@ -1986,7 +1978,7 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY)
                EG(This) = current_this;
                EG(scope) = current_scope;
        }
-       zend_ptr_stack_3_pop(&EG(arg_types_stack), (void**)&EX(calling_scope), (void**)&EX(object), (void**)&EX(fbc));
+       zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc));
 
        EX(function_state).function = (zend_function *) EX(op_array);
        EG(function_state_ptr) = &EX(function_state);
@@ -2014,14 +2006,13 @@ ZEND_VM_HANDLER(60, ZEND_DO_FCALL, CONST, ANY)
        zend_free_op free_op1;
        zval *fname = GET_OP1_ZVAL_PTR(BP_VAR_R);
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        if (zend_u_hash_find(EG(function_table), Z_TYPE_P(fname), Z_UNIVAL_P(fname), Z_UNILEN_P(fname)+1, (void **) &EX(function_state).function)==FAILURE) {
                /* FIXME: output identifiers properly */
                zend_error_noreturn(E_ERROR, "Unknown function:  %R()", Z_TYPE_P(fname), Z_UNIVAL_P(fname));
        }
        EX(object) = NULL;
-       EX(calling_scope) = EX(function_state).function->common.scope;
 
        FREE_OP1();
 
@@ -2478,17 +2469,12 @@ ZEND_VM_HANDLER(68, ZEND_NEW, ANY, ANY)
                EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr;
                EX_T(opline->result.u.var).var.ptr = object_zval;
                
-               zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+               zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), opline);
 
                /* We are not handling overloaded classes right now */
                EX(object) = object_zval;
                EX(fbc) = constructor;
 
-               if (constructor->type == ZEND_USER_FUNCTION) { /* HACK!! */
-                       EX(calling_scope) = constructor->common.scope;
-               } else {
-                       EX(calling_scope) = NULL;
-               }
                ZEND_VM_NEXT_OPCODE();
        }
 }
@@ -3762,10 +3748,15 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
        }
 
        while (EX(fbc)) {
+               zend_op *ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack));
+
                if (EX(object)) {
+                       if (ctor_opline && RETURN_VALUE_USED(ctor_opline)) {
+                               EX(object)->refcount--;
+                       }
                        zval_ptr_dtor(&EX(object));
                }
-               zend_ptr_stack_n_pop(&EG(arg_types_stack), 3, &EX(calling_scope), &EX(object), &EX(fbc));
+               zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc));
        }
 
        /* restore previous error_reporting value */
index 4ce2d364b1805026875f2e81b6e84ac56502972e..6abe2d6b2ee5c3e9524654ed27136da9a9320df9 100644 (file)
@@ -133,6 +133,7 @@ static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
        zval *current_this;
        int return_value_used = RETURN_VALUE_USED(opline);
        zend_bool should_change_scope;
+       zend_op *ctor_opline;
 
        if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) {
                /* FIXME: output identifiers properly */
@@ -150,7 +151,7 @@ static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
                current_this = EG(This);
                EG(This) = EX(object);
                current_scope = EG(scope);
-               EG(scope) = EX(calling_scope);
+               EG(scope) = (EX(function_state).function->type == ZEND_USER_FUNCTION || !EX(object)) ? EX(function_state).function->common.scope : NULL;
        } else {
                should_change_scope = 0;
        }
@@ -279,16 +280,18 @@ static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
+       ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack));
+
        if (EG(This)) {
-               if (EG(exception) && EX(fbc) && EX(fbc)->common.fn_flags&ZEND_ACC_CTOR) {
-                       EG(This)->refcount--;
+               if (EG(exception) && ctor_opline) {
+                       if (RETURN_VALUE_USED(ctor_opline)) {
+                               EG(This)->refcount--;
+                       }
                        if (EG(This)->refcount == 1) {
                                zend_object_store_ctor_failed(EG(This) TSRMLS_CC);
                        }
-                       if (should_change_scope && EG(This) != current_this) {
-                               zval_ptr_dtor(&EG(This));
-                       }
-               } else if (should_change_scope) {
+               }
+               if (should_change_scope) {
                        zval_ptr_dtor(&EG(This));
                }
        }
@@ -297,7 +300,7 @@ static int zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS)
                EG(This) = current_this;
                EG(scope) = current_scope;
        }
-       zend_ptr_stack_3_pop(&EG(arg_types_stack), (void**)&EX(calling_scope), (void**)&EX(object), (void**)&EX(fbc));
+       zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc));
 
        EX(function_state).function = (zend_function *) EX(op_array);
        EG(function_state_ptr) = &EX(function_state);
@@ -419,17 +422,12 @@ static int ZEND_NEW_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                EX_T(opline->result.u.var).var.ptr_ptr = &EX_T(opline->result.u.var).var.ptr;
                EX_T(opline->result.u.var).var.ptr = object_zval;
                
-               zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+               zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), opline);
 
                /* We are not handling overloaded classes right now */
                EX(object) = object_zval;
                EX(fbc) = constructor;
 
-               if (constructor->type == ZEND_USER_FUNCTION) { /* HACK!! */
-                       EX(calling_scope) = constructor->common.scope;
-               } else {
-                       EX(calling_scope) = NULL;
-               }
                ZEND_VM_NEXT_OPCODE();
        }
 }
@@ -557,10 +555,15 @@ static int ZEND_HANDLE_EXCEPTION_SPEC_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        }
 
        while (EX(fbc)) {
+               zend_op *ctor_opline = (zend_op*)zend_ptr_stack_pop(&EG(arg_types_stack));
+
                if (EX(object)) {
+                       if (ctor_opline && RETURN_VALUE_USED(ctor_opline)) {
+                               EX(object)->refcount--;
+                       }
                        zval_ptr_dtor(&EX(object));
                }
-               zend_ptr_stack_n_pop(&EG(arg_types_stack), 3, &EX(calling_scope), &EX(object), &EX(fbc));
+               zend_ptr_stack_2_pop(&EG(arg_types_stack), (void**)&EX(object), (void**)&EX(fbc));
        }
 
        /* restore previous error_reporting value */
@@ -639,7 +642,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_A
        zval *function_name;
        zend_class_entry *ce;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        ce = EX_T(opline->op1.u.var).class_entry;
        if(IS_CONST != IS_UNUSED) {
@@ -673,8 +676,6 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_A
                EX(fbc) = ce->constructor;
        }
 
-       EX(calling_scope) = EX(fbc)->common.scope;
-
        if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) {
                EX(object) = NULL;
        } else {
@@ -695,7 +696,7 @@ static int ZEND_INIT_FCALL_BY_NAME_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        unsigned int function_name_strlen, lcname_len;
        
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        if (IS_CONST == IS_CONST) {
                function_name = &opline->op2.u.constant;
@@ -720,7 +721,6 @@ static int ZEND_INIT_FCALL_BY_NAME_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
 
        }
 
-       EX(calling_scope) = function->common.scope;
        EX(object) = NULL;
 
        EX(fbc) = function;
@@ -835,7 +835,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG
        zval *function_name;
        zend_class_entry *ce;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        ce = EX_T(opline->op1.u.var).class_entry;
        if(IS_TMP_VAR != IS_UNUSED) {
@@ -869,8 +869,6 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG
                EX(fbc) = ce->constructor;
        }
 
-       EX(calling_scope) = EX(fbc)->common.scope;
-
        if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) {
                EX(object) = NULL;
        } else {
@@ -891,7 +889,7 @@ static int ZEND_INIT_FCALL_BY_NAME_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        unsigned int function_name_strlen, lcname_len;
        zend_free_op free_op2;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        if (IS_TMP_VAR == IS_CONST) {
                function_name = &opline->op2.u.constant;
@@ -916,7 +914,6 @@ static int ZEND_INIT_FCALL_BY_NAME_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                zval_dtor(free_op2.var);
        }
 
-       EX(calling_scope) = function->common.scope;
        EX(object) = NULL;
 
        EX(fbc) = function;
@@ -988,7 +985,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG
        zval *function_name;
        zend_class_entry *ce;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        ce = EX_T(opline->op1.u.var).class_entry;
        if(IS_VAR != IS_UNUSED) {
@@ -1022,8 +1019,6 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG
                EX(fbc) = ce->constructor;
        }
 
-       EX(calling_scope) = EX(fbc)->common.scope;
-
        if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) {
                EX(object) = NULL;
        } else {
@@ -1044,7 +1039,7 @@ static int ZEND_INIT_FCALL_BY_NAME_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        unsigned int function_name_strlen, lcname_len;
        zend_free_op free_op2;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        if (IS_VAR == IS_CONST) {
                function_name = &opline->op2.u.constant;
@@ -1069,7 +1064,6 @@ static int ZEND_INIT_FCALL_BY_NAME_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                if (free_op2.var) {zval_ptr_dtor(&free_op2.var);};
        }
 
-       EX(calling_scope) = function->common.scope;
        EX(object) = NULL;
 
        EX(fbc) = function;
@@ -1140,7 +1134,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_
        zval *function_name;
        zend_class_entry *ce;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        ce = EX_T(opline->op1.u.var).class_entry;
        if(IS_UNUSED != IS_UNUSED) {
@@ -1174,8 +1168,6 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_UNUSED_HANDLER(ZEND_OPCODE_HANDLER_
                EX(fbc) = ce->constructor;
        }
 
-       EX(calling_scope) = EX(fbc)->common.scope;
-
        if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) {
                EX(object) = NULL;
        } else {
@@ -1223,7 +1215,7 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS
        zval *function_name;
        zend_class_entry *ce;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        ce = EX_T(opline->op1.u.var).class_entry;
        if(IS_CV != IS_UNUSED) {
@@ -1257,8 +1249,6 @@ static int ZEND_INIT_STATIC_METHOD_CALL_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS
                EX(fbc) = ce->constructor;
        }
 
-       EX(calling_scope) = EX(fbc)->common.scope;
-
        if (EX(fbc)->common.fn_flags & ZEND_ACC_STATIC) {
                EX(object) = NULL;
        } else {
@@ -1279,7 +1269,7 @@ static int ZEND_INIT_FCALL_BY_NAME_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        unsigned int function_name_strlen, lcname_len;
        
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        if (IS_CV == IS_CONST) {
                function_name = &opline->op2.u.constant;
@@ -1304,7 +1294,6 @@ static int ZEND_INIT_FCALL_BY_NAME_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
 
        }
 
-       EX(calling_scope) = function->common.scope;
        EX(object) = NULL;
 
        EX(fbc) = function;
@@ -1372,11 +1361,11 @@ static int ZEND_ECHO_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* Convert inline HTML blocks to the output encoding, but only if necessary. */
        if (opline->extended_value &&
                strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status),
-                          EG(active_op_array)->script_encoding)) {
+                          EX(op_array)->script_encoding)) {
                zval z_conv;
                UConverter *script_enc_conv = NULL;
-               if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) {
-                       zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding);
+               if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) {
+                       zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding);
                }
                zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status);
                z_conv.type = IS_BINARY;
@@ -1621,14 +1610,13 @@ static int ZEND_DO_FCALL_SPEC_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        
        zval *fname = &opline->op1.u.constant;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        if (zend_u_hash_find(EG(function_table), Z_TYPE_P(fname), Z_UNIVAL_P(fname), Z_UNILEN_P(fname)+1, (void **) &EX(function_state).function)==FAILURE) {
                /* FIXME: output identifiers properly */
                zend_error_noreturn(E_ERROR, "Unknown function:  %R()", Z_TYPE_P(fname), Z_UNIVAL_P(fname));
        }
        EX(object) = NULL;
-       EX(calling_scope) = EX(function_state).function->common.scope;
 
        return zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
 }
@@ -3878,11 +3866,11 @@ static int ZEND_ECHO_SPEC_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* Convert inline HTML blocks to the output encoding, but only if necessary. */
        if (opline->extended_value &&
                strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status),
-                          EG(active_op_array)->script_encoding)) {
+                          EX(op_array)->script_encoding)) {
                zval z_conv;
                UConverter *script_enc_conv = NULL;
-               if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) {
-                       zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding);
+               if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) {
+                       zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding);
                }
                zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status);
                z_conv.type = IS_BINARY;
@@ -5146,7 +5134,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = &opline->op2.u.constant;
 
@@ -5157,8 +5145,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -5189,12 +5175,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
 
        ZEND_VM_NEXT_OPCODE();
 }
@@ -5589,7 +5569,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
 
@@ -5600,8 +5580,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -5632,12 +5610,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        zval_dtor(free_op2.var);
 
        ZEND_VM_NEXT_OPCODE();
@@ -6034,7 +6006,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
 
@@ -6045,8 +6017,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -6077,12 +6047,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        if (free_op2.var) {zval_ptr_dtor(&free_op2.var);};
 
        ZEND_VM_NEXT_OPCODE();
@@ -6561,7 +6525,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC);
 
@@ -6572,8 +6536,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_tmp(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -6604,12 +6566,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_TMP_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
 
        ZEND_VM_NEXT_OPCODE();
 }
@@ -6923,11 +6879,11 @@ static int ZEND_ECHO_SPEC_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* Convert inline HTML blocks to the output encoding, but only if necessary. */
        if (opline->extended_value &&
                strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status),
-                          EG(active_op_array)->script_encoding)) {
+                          EX(op_array)->script_encoding)) {
                zval z_conv;
                UConverter *script_enc_conv = NULL;
-               if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) {
-                       zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding);
+               if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) {
+                       zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding);
                }
                zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status);
                z_conv.type = IS_BINARY;
@@ -9140,7 +9096,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = &opline->op2.u.constant;
 
@@ -9151,8 +9107,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -9183,12 +9137,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
 
        ZEND_VM_NEXT_OPCODE();
@@ -10635,7 +10583,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
 
@@ -10646,8 +10594,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -10678,12 +10624,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        zval_dtor(free_op2.var);
        if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
 
@@ -12170,7 +12110,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
 
@@ -12181,8 +12121,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -12213,12 +12151,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        if (free_op2.var) {zval_ptr_dtor(&free_op2.var);};
        if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
 
@@ -14111,7 +14043,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC);
 
@@ -14122,8 +14054,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_var(&opline->op1, EX(Ts), &free_op1 TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -14154,12 +14084,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_VAR_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        if (free_op1.var) {zval_ptr_dtor(&free_op1.var);};
 
        ZEND_VM_NEXT_OPCODE();
@@ -15326,7 +15250,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_CONST_HANDLER(ZEND_OPCODE_HANDLER_A
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = &opline->op2.u.constant;
 
@@ -15337,8 +15261,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_CONST_HANDLER(ZEND_OPCODE_HANDLER_A
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -15369,12 +15291,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_CONST_HANDLER(ZEND_OPCODE_HANDLER_A
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
 
        ZEND_VM_NEXT_OPCODE();
 }
@@ -16476,7 +16392,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
 
@@ -16487,8 +16403,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -16519,12 +16433,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARG
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        zval_dtor(free_op2.var);
 
        ZEND_VM_NEXT_OPCODE();
@@ -17584,7 +17492,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
 
@@ -17595,8 +17503,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -17627,12 +17533,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARG
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        if (free_op2.var) {zval_ptr_dtor(&free_op2.var);};
 
        ZEND_VM_NEXT_OPCODE();
@@ -19058,7 +18958,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC);
 
@@ -19069,8 +18969,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_obj_zval_ptr_unused(TSRMLS_C);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -19101,12 +18999,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_UNUSED_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
 
        ZEND_VM_NEXT_OPCODE();
 }
@@ -19696,11 +19588,11 @@ static int ZEND_ECHO_SPEC_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* Convert inline HTML blocks to the output encoding, but only if necessary. */
        if (opline->extended_value &&
                strcmp(ucnv_getName(ZEND_U_CONVERTER(UG(output_encoding_conv)), &status),
-                          EG(active_op_array)->script_encoding)) {
+                          EX(op_array)->script_encoding)) {
                zval z_conv;
                UConverter *script_enc_conv = NULL;
-               if (zend_set_converter_encoding(&script_enc_conv, EG(active_op_array)->script_encoding) == FAILURE) {
-                       zend_error(E_ERROR, "Unsupported encoding [%d]", EG(active_op_array)->script_encoding);
+               if (zend_set_converter_encoding(&script_enc_conv, EX(op_array)->script_encoding) == FAILURE) {
+                       zend_error(E_ERROR, "Unsupported encoding [%d]", EX(op_array)->script_encoding);
                }
                zend_convert_encodings(ZEND_U_CONVERTER(UG(output_encoding_conv)), script_enc_conv, &z_conv.value.str.val, &z_conv.value.str.len, z->value.str.val, z->value.str.len, &status);
                z_conv.type = IS_BINARY;
@@ -21737,7 +21629,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = &opline->op2.u.constant;
 
@@ -21748,8 +21640,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -21780,12 +21670,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_CONST_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
 
        ZEND_VM_NEXT_OPCODE();
 }
@@ -23224,7 +23108,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_tmp(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
 
@@ -23235,8 +23119,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -23267,12 +23149,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_TMP_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        zval_dtor(free_op2.var);
 
        ZEND_VM_NEXT_OPCODE();
@@ -24750,7 +24626,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_var(&opline->op2, EX(Ts), &free_op2 TSRMLS_CC);
 
@@ -24761,8 +24637,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -24793,12 +24667,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_VAR_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
        if (free_op2.var) {zval_ptr_dtor(&free_op2.var);};
 
        ZEND_VM_NEXT_OPCODE();
@@ -26681,7 +26549,7 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        /* FIXME: type is default */
        zend_uchar type = UG(unicode)?IS_UNICODE:IS_STRING;
 
-       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), EX(calling_scope));
+       zend_ptr_stack_3_push(&EG(arg_types_stack), EX(fbc), EX(object), NULL);
 
        function_name = _get_zval_ptr_cv(&opline->op2, EX(Ts), BP_VAR_R TSRMLS_CC);
 
@@ -26692,8 +26560,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
        function_name_strval = Z_UNIVAL_P(function_name);
        function_name_strlen = Z_UNILEN_P(function_name);
 
-       EX(calling_scope) = EG(scope);
-
        EX(object) = _get_zval_ptr_cv(&opline->op1, EX(Ts), BP_VAR_R TSRMLS_CC);
 
        if (EX(object) && EX(object)->type == IS_OBJECT) {
@@ -26724,12 +26590,6 @@ static int ZEND_INIT_METHOD_CALL_SPEC_CV_CV_HANDLER(ZEND_OPCODE_HANDLER_ARGS)
                }
        }
 
-       if (EX(fbc)->type == ZEND_USER_FUNCTION) {
-               EX(calling_scope) = EX(fbc)->common.scope;
-       } else {
-               EX(calling_scope) = NULL;
-       }
-
 
        ZEND_VM_NEXT_OPCODE();
 }