[php-src] master: Merge branch 'PHP-8.6'
| From: | Ilia Alshanetsky | Date: | Sun, 22 Nov 2026 23:17:02 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-144048@lists.php.net to get a copy of this message | ||
Author: Ilia Alshanetsky (iliaal)
Date: 2026-11-22T18:13:42-05:00
Commit: https://github.com/php/php-src/commit/96493f5d6f3615e0d9a263c6b2bcfbbba1e810aa
Raw diff: https://github.com/php/php-src/commit/96493f5d6f3615e0d9a263c6b2bcfbbba1e810aa.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
Zend/Optimizer: Keep by-ref containers out of converted FUNC_ARG fetches
Changed paths:
A ext/opcache/tests/opt/gh25449.phpt
M Zend/Optimizer/optimize_func_calls.c
Diff:
diff --git a/Zend/Optimizer/optimize_func_calls.c b/Zend/Optimizer/optimize_func_calls.c
index 4275bdb4071c..375e9d523f9c 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 000000000000..027fc09d731b
--- /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 ®istry(): 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