Skip to content
Open
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
4 changes: 2 additions & 2 deletions Zend/Optimizer/block_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
} else if (opline->op1_type == IS_TMP_VAR &&
!zend_bitset_in(used_ext, VAR_NUM(opline->op1.var))) {
src = VAR_SOURCE(opline->op1);
if (src) {
if (src && src->op1_type != IS_VAR) {
if (src->opcode == ZEND_BOOL_NOT) {
VAR_SOURCE(opline->op1) = NULL;
COPY_NODE(opline->op1, src->op1);
Expand Down Expand Up @@ -747,7 +747,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
(!zend_bitset_in(used_ext, VAR_NUM(opline->op1.var)) ||
opline->result.var == opline->op1.var)) {
src = VAR_SOURCE(opline->op1);
if (src) {
if (src && src->op1_type != IS_VAR) {
if (src->opcode == ZEND_BOOL ||
src->opcode == ZEND_QM_ASSIGN) {
VAR_SOURCE(opline->op1) = NULL;
Expand Down
42 changes: 42 additions & 0 deletions ext/opcache/tests/gh21691.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
GH-21691 (OPcache CFG optimizer breaks reference returns with JMPZ/JMPZ_EX)
--INI--
opcache.enable_cli=1
--EXTENSIONS--
opcache
--FILE--
<?php
class Base {
protected function &getData(): array {
$x = [];
return $x;
}

public function process(): array {
if ($data = &$this->getData() && !isset($data['key'])) {
}
return $data;
}

public function check(): bool {
return ($data = &$this->getData()) && count($data) > 0;
}
}

class Child extends Base {
protected function &getData(): array {
static $x = ['value' => 42];
return $x;
}
}

$child = new Child();
var_dump($child->process());
var_dump($child->check());
?>
--EXPECT--
array(1) {
["value"]=>
int(42)
}
bool(true)
Loading