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/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -4209,7 +4209,7 @@ ZEND_VM_HOT_HANDLER(130, ZEND_DO_UCALL, ANY, ANY, SPEC(RETVAL,OBSERVER))

call->prev_execute_data = execute_data;
execute_data = call;
i_init_func_execute_data(&fbc->op_array, ret, 0 EXECUTE_DATA_CC);
i_init_func_execute_data(&fbc->op_array, ret, 1 EXECUTE_DATA_CC);
LOAD_OPLINE_EX();
ZEND_OBSERVER_SAVE_OPLINE();
ZEND_OBSERVER_FCALL_BEGIN(execute_data);
Expand Down
12 changes: 6 additions & 6 deletions Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions ext/opcache/tests/func_call_ref_return_overridden.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
--TEST--
DO_UCALL must not be used for functions returning by reference
--DESCRIPTION--
The optimizer's zend_get_call_op() converts DO_FCALL to DO_UCALL for user
functions, but DO_UCALL hardcodes return_reference=0 in
i_init_func_execute_data(). When the called function returns by reference
(e.g. an overridden method using ASSIGN_REF), this produces invalid opcode
sequences. The fix is either to not use DO_UCALL when the function has
ZEND_ACC_RETURN_REFERENCE, or to make DO_UCALL honor it.
--FILE--
<?php
class Base {
protected function &getData(): array {
$x = [];
return $x;
}

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

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

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