Commit 12d9e404010 for php

commit 12d9e404010187380ab038fbd065f35e1b31baab
Author: Ilia Alshanetsky <ilia@ilia.ws>
Date:   Sat Nov 14 08:52:29 2026 -0500

    Zend/Optimizer: Keep by-ref containers out of converted FUNC_ARG fetches

    Pass 4 can convert a by-value argument fetch to a read while its VAR
    container still holds a reference. Retype call results to TMP so the VM
    unwraps them. Keep the FUNC_ARG fetch when the container comes from any
    other producer except an already converted read fetch.

    Fixes GH-25449
    Closes GH-25458

diff --git a/NEWS b/NEWS
index cecd5dff170..e4554634880 100644
--- a/NEWS
+++ b/NEWS
@@ -128,6 +128,8 @@ PHP                                                                        NEWS
     arrays. (Weilin Du)
   . Fixed function JIT ASSIGN_DIM reporting an undefined value or key out of
     order, or when the VM does not, on non-array containers. (Jorg Sowa)
+  . Fixed bug GH-25449 (Element of a by-reference function result passed as
+    an argument arrives as null). (Ilia Alshanetsky)

 - OpenSSL:
   . Fixed bug GH-25172 (TLS session reuse shares request-lifetime callback
diff --git a/Zend/Optimizer/optimize_func_calls.c b/Zend/Optimizer/optimize_func_calls.c
index 4275bdb4071..375e9d523f9 100644
--- a/Zend/Optimizer/optimize_func_calls.c
+++ b/Zend/Optimizer/optimize_func_calls.c
@@ -76,6 +76,34 @@ static void zend_delete_call_instructions(const zend_op_array *op_array, zend_op
 	}
 }

+static bool zend_fetch_func_arg_container_to_r(const zend_op_array *op_array, zend_op *opline)
+{
+	zend_op *def = opline;
+
+	while (def > op_array->opcodes) {
+		def--;
+		if (def->result_type == IS_VAR && def->result.var == opline->op1.var) {
+			switch (def->opcode) {
+				case ZEND_DO_FCALL:
+				case ZEND_DO_ICALL:
+				case ZEND_DO_UCALL:
+				case ZEND_DO_FCALL_BY_NAME:
+					def->result_type = IS_TMP_VAR;
+					opline->op1_type = IS_TMP_VAR;
+					return true;
+				case ZEND_FETCH_R:
+				case ZEND_FETCH_DIM_R:
+				case ZEND_FETCH_OBJ_R:
+				case ZEND_FETCH_STATIC_PROP_R:
+					return true;
+				default:
+					return false;
+			}
+		}
+	}
+	return false;
+}
+
 static void zend_try_inline_call(zend_op_array *op_array, const zend_op *fcall, zend_op *opline, const zend_function *func)
 {
 	const uint32_t no_discard = RETURN_VALUE_USED(opline) ? 0 : ZEND_ACC_NODISCARD;
@@ -274,6 +302,14 @@ void zend_optimize_func_calls(zend_op_array *op_array, zend_optimizer_ctx *ctx)
 							break;
 						}

+						if ((opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG || opline->opcode == ZEND_FETCH_DIM_FUNC_ARG)
+						 && opline->op1_type == IS_VAR
+						 && !zend_fetch_func_arg_container_to_r(op_array, opline)) {
+							call_stack[call - 1].try_inline = false;
+							call_stack[call - 1].last_check_func_arg_opline = NULL;
+							break;
+						}
+
 						if (opline->opcode != ZEND_FETCH_STATIC_PROP_FUNC_ARG) {
 							opline->opcode -= 12;
 						} else {
diff --git a/ext/opcache/tests/opt/gh25449.phpt b/ext/opcache/tests/opt/gh25449.phpt
new file mode 100644
index 00000000000..027fc09d731
--- /dev/null
+++ b/ext/opcache/tests/opt/gh25449.phpt
@@ -0,0 +1,66 @@
+--TEST--
+GH-25449 (Fetch on a by-reference call result passed as a by-value argument)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.file_update_protection=0
+--EXTENSIONS--
+opcache
+--FILE--
+<?php
+function &registry(): array {
+    static $r = ['k' => 'func'];
+    return $r;
+}
+
+class K {
+    public $p = ['k' => 'prop'];
+
+    public static function &staticRef(): array {
+        static $r = ['k' => 'static'];
+        return $r;
+    }
+
+    public function &methodRef(): array {
+        return $this->p;
+    }
+
+    public function &self(): K {
+        return $this;
+    }
+}
+
+function dim(): string { return consume(registry()['k']); }
+function staticDim(): string { return consume(K::staticRef()['k']); }
+function methodDim(K $o): string { return consume($o->methodRef()['k']); }
+function objDim(K $o): string { return consume($o->self()->p['k']); }
+function chainedDim(): string { return consume(registry()['k'][0]); }
+function closureDim(Closure $c): string { return consume($c()['k']); }
+function assignRefDim(): string { $x = ['k' => 'assign-ref']; return consume(($y = &$x)['k']); }
+function assignRefObj(): string { $x = new K; return consume(($y = &$x)->p['k']); }
+function listRefDim(): string { $a = ['x' => ['k' => 'list-ref']]; return consume((['x' => &$z] = $a)['x']['k']); }
+
+function consume(string $s): string { return $s; }
+
+$o = new K;
+echo "dim: ", dim(), "\n";
+echo "static: ", staticDim(), "\n";
+echo "method: ", methodDim($o), "\n";
+echo "obj: ", objDim($o), "\n";
+echo "chained: ", chainedDim(), "\n";
+echo "closure: ", closureDim(function &(): array { return registry(); }), "\n";
+echo "assign-ref: ", assignRefDim(), "\n";
+echo "assign-ref obj: ", assignRefObj(), "\n";
+echo "list-ref: ", listRefDim(), "\n";
+?>
+--EXPECT--
+dim: func
+static: static
+method: prop
+obj: prop
+chained: f
+closure: func
+assign-ref: assign-ref
+assign-ref obj: prop
+list-ref: list-ref