Commit 16c466297b4 for php

commit 16c466297b4ebf62b511e060d227b62f6724d4a7
Author: Ilia Alshanetsky <ilia@ilia.ws>
Date:   Thu Nov 26 18:21:57 2026 -0500

    ext/opcache: Do not drop QM_ASSIGN of IS_VAR before ZEND_RETURN

    Keep the dereferencing QM_ASSIGN when its source is IS_VAR. ZEND_RETURN
    only accepts CONST, TMP, and CV, so folding the assignment into the
    return can produce an invalid opcode for by-reference assignments or
    list destructuring.

    Fixes GH-25756
    Closes GH-25814

diff --git a/NEWS b/NEWS
index 2dfdf7e9b21..b8b694d06dd 100644
--- a/NEWS
+++ b/NEWS
@@ -186,6 +186,8 @@ PHP                                                                        NEWS
   . Fix JIT register allocation for ASSIGN to traced reference. (ndossche)
   . Fixed a double free when a destructor throws while freeing a temporary
     whose result the optimizer discarded. (Ilia Alshanetsky)
+  . Fixed bug GH-25756 (OPcache: "Invalid opcode 62/4/0" when assigning a
+    reference in a return). (Ilia Alshanetsky, Pratik Bhujel)

 - OpenSSL:
   . Fixed bug GH-25172 (TLS session reuse shares request-lifetime callback
diff --git a/Zend/Optimizer/block_pass.c b/Zend/Optimizer/block_pass.c
index 0601994479e..f790c3bf620 100644
--- a/Zend/Optimizer/block_pass.c
+++ b/Zend/Optimizer/block_pass.c
@@ -910,7 +910,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
 			case ZEND_RETURN:
 				if (opline->op1_type == IS_TMP_VAR) {
 					src = VAR_SOURCE(opline->op1);
-					if (src && src->opcode == ZEND_QM_ASSIGN) {
+					if (src && src->opcode == ZEND_QM_ASSIGN && src->op1_type != IS_VAR) {
 						zend_op *op = src + 1;
 						bool optimize = true;

diff --git a/ext/opcache/tests/gh25756.phpt b/ext/opcache/tests/gh25756.phpt
new file mode 100644
index 00000000000..30fb73083c4
--- /dev/null
+++ b/ext/opcache/tests/gh25756.phpt
@@ -0,0 +1,99 @@
+--TEST--
+GH-25756 (OPcache: "Invalid opcode 62/4/0" when assigning a reference in a return)
+--EXTENSIONS--
+opcache
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+--FILE--
+<?php
+
+function test_assign_ref() {
+    $b = 'success';
+    return $a = &$b;
+}
+
+function &get_ref() {
+    static $x = 'from_func';
+    return $x;
+}
+
+function test_assign_func_ref() {
+    return $a = &get_ref();
+}
+
+function test_assign_obj_ref(stdClass $obj, &$b) {
+    return $obj->p = &$b;
+}
+
+function test_assign_dim_ref() {
+    $b = 'dim_val';
+    $arr = [];
+    return $arr[0] = &$b;
+}
+
+class StaticPropHolder {
+    public static $p;
+}
+
+function test_assign_static_prop_ref(&$b) {
+    return StaticPropHolder::$p = &$b;
+}
+
+function test_list_by_ref() {
+    $arr = ['list_val'];
+    return [&$a] = $arr;
+}
+
+function test_ternary_assign_ref(bool $cond) {
+    $b = 'ternary_val';
+    return $cond ? ($a = &$b) : 'other';
+}
+
+function test_match_assign_ref(bool $cond) {
+    $b = 'match_val';
+    return match ($cond) {
+        true => $a = &$b,
+        default => 'other',
+    };
+}
+
+function test_typed_assign_ref(): string {
+    $b = 'typed_val';
+    return $a = &$b;
+}
+
+$obj = new stdClass();
+$obj_src = 'obj_prop';
+$obj_ret = test_assign_obj_ref($obj, $obj_src);
+$obj_src = 'obj_changed';
+
+$static_src = 'static_prop';
+$static_ret = test_assign_static_prop_ref($static_src);
+$static_src = 'static_changed';
+
+$arrow_src = 'arrow_val';
+$arrow = fn() => $a = &$arrow_src;
+
+echo "1: ", test_assign_ref(), "\n";
+echo "2: ", test_assign_func_ref(), "\n";
+echo "3: ", $obj_ret, " / ", $obj->p, "\n";
+echo "4: ", test_assign_dim_ref(), "\n";
+echo "5: ", $static_ret, " / ", StaticPropHolder::$p, "\n";
+echo "6: ", implode(',', test_list_by_ref()), "\n";
+echo "7: ", test_ternary_assign_ref(true), "\n";
+echo "8: ", test_match_assign_ref(true), "\n";
+echo "9: ", test_typed_assign_ref(), "\n";
+echo "10: ", $arrow(), "\n";
+?>
+--EXPECT--
+1: success
+2: from_func
+3: obj_prop / obj_changed
+4: dim_val
+5: static_prop / static_changed
+6: list_val
+7: ternary_val
+8: match_val
+9: typed_val
+10: arrow_val