Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ PHP NEWS
. Fixed tracing JIT taking the wrong branch after a VM interrupt.
(Brian Marks)
. Fix JIT register allocation for ASSIGN to traced reference. (ndossche)
. 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
Expand Down
2 changes: 1 addition & 1 deletion Zend/Optimizer/block_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
99 changes: 99 additions & 0 deletions ext/opcache/tests/gh25756.phpt
Original file line number Diff line number Diff line change
@@ -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
Loading