diff --git a/ext/opcache/jit/zend_jit_ir.c b/ext/opcache/jit/zend_jit_ir.c index cc3b867b2f27..cd261b9dddf9 100644 --- a/ext/opcache/jit/zend_jit_ir.c +++ b/ext/opcache/jit/zend_jit_ir.c @@ -9389,7 +9389,8 @@ static int zend_jit_init_static_method_call(zend_jit_ctx *jit, (opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF)) { if (op_array->fn_flags & ZEND_ACC_STATIC) { scope_ref = ir_LOAD_A(jit_EX(This.value.ref)); - } else if (op_array->fn_flags & ZEND_ACC_CLOSURE) { + } else if ((op_array->fn_flags & ZEND_ACC_CLOSURE) || !op_array->function_name) { + /* Closured can be unbound, file/eval inherits This from the existing frame's scope. */ ir_ref if_object, values = IR_UNUSED; if_object = ir_IF(ir_EQ(jit_Z_TYPE_ref(jit, jit_EX(This)), ir_CONST_U8(IS_OBJECT))); diff --git a/ext/opcache/tests/jit/init_static_method_call_002.phpt b/ext/opcache/tests/jit/init_static_method_call_002.phpt new file mode 100644 index 000000000000..897c0377d6c3 --- /dev/null +++ b/ext/opcache/tests/jit/init_static_method_call_002.phpt @@ -0,0 +1,32 @@ +--TEST-- +JIT INIT_STATIC_METHOD_CALL: self:: in an included file keeps the called scope of a static caller +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit=tracing +opcache.jit_hot_loop=1 +--EXTENSIONS-- +opcache +--FILE-- + +--EXPECT-- +B +B +B diff --git a/ext/opcache/tests/jit/init_static_method_call_002_include.inc b/ext/opcache/tests/jit/init_static_method_call_002_include.inc new file mode 100644 index 000000000000..66ea277d2da9 --- /dev/null +++ b/ext/opcache/tests/jit/init_static_method_call_002_include.inc @@ -0,0 +1,4 @@ +