From 29d8a43b21fd6f95e0325c8b10ffe30d37b273b4 Mon Sep 17 00:00:00 2001 From: ndossche <7771979+ndossche@users.noreply.github.com> Date: Thu, 29 Oct 2026 20:55:30 +0100 Subject: [PATCH] Fix JIT losing the called scope of self::/parent:: calls in included files File/eval code take This from the existing frame's scope, so This may be a class instead of an object. --- ext/opcache/jit/zend_jit_ir.c | 3 +- .../jit/init_static_method_call_002.phpt | 32 +++++++++++++++++++ .../init_static_method_call_002_include.inc | 4 +++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 ext/opcache/tests/jit/init_static_method_call_002.phpt create mode 100644 ext/opcache/tests/jit/init_static_method_call_002_include.inc 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 @@ +