Skip to content

Commit e1fb101

Browse files
committed
Merge branch 'PHP-8.6'
* PHP-8.6: ext/opcache: Do not drop QM_ASSIGN of IS_VAR before ZEND_RETURN
2 parents 7a4a62b + 16c4662 commit e1fb101

2 files changed

Lines changed: 100 additions & 1 deletion

File tree

‎Zend/Optimizer/block_pass.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
910910
case ZEND_RETURN:
911911
if (opline->op1_type == IS_TMP_VAR) {
912912
src = VAR_SOURCE(opline->op1);
913-
if (src && src->opcode == ZEND_QM_ASSIGN) {
913+
if (src && src->opcode == ZEND_QM_ASSIGN && src->op1_type != IS_VAR) {
914914
zend_op *op = src + 1;
915915
bool optimize = true;
916916

‎ext/opcache/tests/gh25756.phpt‎

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
--TEST--
2+
GH-25756 (OPcache: "Invalid opcode 62/4/0" when assigning a reference in a return)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
--FILE--
9+
<?php
10+
11+
function test_assign_ref() {
12+
$b = 'success';
13+
return $a = &$b;
14+
}
15+
16+
function &get_ref() {
17+
static $x = 'from_func';
18+
return $x;
19+
}
20+
21+
function test_assign_func_ref() {
22+
return $a = &get_ref();
23+
}
24+
25+
function test_assign_obj_ref(stdClass $obj, &$b) {
26+
return $obj->p = &$b;
27+
}
28+
29+
function test_assign_dim_ref() {
30+
$b = 'dim_val';
31+
$arr = [];
32+
return $arr[0] = &$b;
33+
}
34+
35+
class StaticPropHolder {
36+
public static $p;
37+
}
38+
39+
function test_assign_static_prop_ref(&$b) {
40+
return StaticPropHolder::$p = &$b;
41+
}
42+
43+
function test_list_by_ref() {
44+
$arr = ['list_val'];
45+
return [&$a] = $arr;
46+
}
47+
48+
function test_ternary_assign_ref(bool $cond) {
49+
$b = 'ternary_val';
50+
return $cond ? ($a = &$b) : 'other';
51+
}
52+
53+
function test_match_assign_ref(bool $cond) {
54+
$b = 'match_val';
55+
return match ($cond) {
56+
true => $a = &$b,
57+
default => 'other',
58+
};
59+
}
60+
61+
function test_typed_assign_ref(): string {
62+
$b = 'typed_val';
63+
return $a = &$b;
64+
}
65+
66+
$obj = new stdClass();
67+
$obj_src = 'obj_prop';
68+
$obj_ret = test_assign_obj_ref($obj, $obj_src);
69+
$obj_src = 'obj_changed';
70+
71+
$static_src = 'static_prop';
72+
$static_ret = test_assign_static_prop_ref($static_src);
73+
$static_src = 'static_changed';
74+
75+
$arrow_src = 'arrow_val';
76+
$arrow = fn() => $a = &$arrow_src;
77+
78+
echo "1: ", test_assign_ref(), "\n";
79+
echo "2: ", test_assign_func_ref(), "\n";
80+
echo "3: ", $obj_ret, " / ", $obj->p, "\n";
81+
echo "4: ", test_assign_dim_ref(), "\n";
82+
echo "5: ", $static_ret, " / ", StaticPropHolder::$p, "\n";
83+
echo "6: ", implode(',', test_list_by_ref()), "\n";
84+
echo "7: ", test_ternary_assign_ref(true), "\n";
85+
echo "8: ", test_match_assign_ref(true), "\n";
86+
echo "9: ", test_typed_assign_ref(), "\n";
87+
echo "10: ", $arrow(), "\n";
88+
?>
89+
--EXPECT--
90+
1: success
91+
2: from_func
92+
3: obj_prop / obj_changed
93+
4: dim_val
94+
5: static_prop / static_changed
95+
6: list_val
96+
7: ternary_val
97+
8: match_val
98+
9: typed_val
99+
10: arrow_val

0 commit comments

Comments
 (0)