Skip to content

Commit 15cbd82

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
2 parents 469b7b9 + a480965 commit 15cbd82

4 files changed

Lines changed: 65 additions & 6 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ PHP NEWS
3434
. Fixed bug GH-22265 (Another tailcall vm_interrupt bug). (Levi Morrison)
3535
. Fixed bug GH-20469 (Unsafe inheritance cache replay with reentrant
3636
autoloading). (Levi Morrison)
37+
. Fixed bug GH-21972 (Corrupted variable type when a typed by-value return
38+
contains a reference wrapper). (Weilin Du)
3739

3840
- Phar:
3941
. Fixed a bypass of the magic ".phar" directory protection in

Zend/zend_vm_def.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4454,7 +4454,7 @@ ZEND_VM_COLD_CONST_HANDLER(124, ZEND_VERIFY_RETURN_TYPE, CONST|TMP|VAR|UNUSED|CV
44544454
ZVAL_DEREF(retval_ptr);
44554455
}
44564456

4457-
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(retval_ptr)))) {
4457+
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(retval_ref)))) {
44584458
ZEND_VM_NEXT_OPCODE();
44594459
}
44604460

@@ -4483,6 +4483,9 @@ ZEND_VM_COLD_CONST_HANDLER(124, ZEND_VERIFY_RETURN_TYPE, CONST|TMP|VAR|UNUSED|CV
44834483
}
44844484
retval_ptr = retval_ref;
44854485
}
4486+
if (EXPECTED(ZEND_TYPE_CONTAINS_CODE(ret_info->type, Z_TYPE_P(retval_ptr)))) {
4487+
ZEND_VM_NEXT_OPCODE();
4488+
}
44864489
}
44874490

44884491
SAVE_OPLINE();

Zend/zend_vm_execute.h

Lines changed: 20 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/opcache/tests/opt/gh21972.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
GH-21972: Typed by-value return must not leak reference wrapper
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--EXTENSIONS--
8+
opcache
9+
--FILE--
10+
<?php
11+
declare(strict_types=1);
12+
13+
enum ValueType {
14+
case BOOL;
15+
case MIXED;
16+
}
17+
18+
function applyDefinition(
19+
bool &$lazy = false,
20+
ValueType &$type = ValueType::MIXED,
21+
int &$flags = 0,
22+
?string &$default = null,
23+
): void {
24+
}
25+
26+
function getTypedValue(string $default, bool $lazy, ValueType $type): string {
27+
applyDefinition($lazy, $type, default: $default);
28+
return $default;
29+
}
30+
31+
$value = getTypedValue('false', false, ValueType::BOOL);
32+
var_dump(gettype($value));
33+
var_dump(strtolower($value));
34+
var_dump(strtolower(getTypedValue('FALSE', false, ValueType::BOOL)));
35+
?>
36+
--EXPECT--
37+
string(6) "string"
38+
string(5) "false"
39+
string(5) "false"

0 commit comments

Comments
 (0)