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
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PHP NEWS
. Fix persistent free of non-persistent connect_attr key (David Carlier).

- Opcache:
. Fixed bug GH-21972 (Corrupted variable type when a typed by-value return
contains a reference wrapper). (Weilin Du)
. Fixed tracing JIT crash when a VM interrupt is handled during an observed
user function call. (Levi Morrison)

Expand Down
5 changes: 4 additions & 1 deletion Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -4387,7 +4387,7 @@ ZEND_VM_COLD_CONST_HANDLER(124, ZEND_VERIFY_RETURN_TYPE, CONST|TMP|VAR|UNUSED|CV
ZVAL_DEREF(retval_ptr);
}

if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(retval_ptr)))) {
Comment thread
LamentXU123 marked this conversation as resolved.
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(retval_ref)))) {
ZEND_VM_NEXT_OPCODE();
}

Expand Down Expand Up @@ -4417,6 +4417,9 @@ ZEND_VM_COLD_CONST_HANDLER(124, ZEND_VERIFY_RETURN_TYPE, CONST|TMP|VAR|UNUSED|CV
}
retval_ptr = retval_ref;
}
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(retval_ptr)))) {
ZEND_VM_NEXT_OPCODE();
}
}

SAVE_OPLINE();
Expand Down
25 changes: 20 additions & 5 deletions Zend/zend_vm_execute.h

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

39 changes: 39 additions & 0 deletions ext/opcache/tests/opt/gh21972.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--TEST--
GH-21972: Typed by-value return must not leak reference wrapper
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
--EXTENSIONS--
opcache
--FILE--
<?php
declare(strict_types=1);

enum ValueType {
case BOOL;
case MIXED;
}

function applyDefinition(
bool &$lazy = false,
ValueType &$type = ValueType::MIXED,
int &$flags = 0,
?string &$default = null,
): void {
}

function getTypedValue(string $default, bool $lazy, ValueType $type): string {
applyDefinition($lazy, $type, default: $default);
return $default;
}

$value = getTypedValue('false', false, ValueType::BOOL);
var_dump(gettype($value));
var_dump(strtolower($value));
var_dump(strtolower(getTypedValue('FALSE', false, ValueType::BOOL)));
?>
--EXPECT--
string(6) "string"
string(5) "false"
string(5) "false"