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: 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
49 changes: 49 additions & 0 deletions ext/opcache/tests/gh25756.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--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_return_ref_assign() {
$variable_2 = 'success';
return $variable_1 = &$variable_2;
}

function test_arrow_fn_ref_assign() {
$variable_2 = 'arrow';
$fn = fn() => $variable_1 = &$variable_2;
return $fn();
}

function test_match_ref_assign() {
$variable_2 = 'match';
return match (1) {
1 => $variable_1 = &$variable_2,
};
}

function test_return_unwraps_ref(&$out) {
$out = 'before';
return $local = &$out;
}

echo test_return_ref_assign(), "\n";
echo test_arrow_fn_ref_assign(), "\n";
echo test_match_ref_assign(), "\n";

$ref = null;
$val = test_return_unwraps_ref($ref);
$ref = 'after';
var_dump($val, $ref);

?>
--EXPECT--
success
arrow
match
string(6) "before"
string(5) "after"
Loading