Skip to content

Commit 177a6f5

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fixed GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
2 parents a39e869 + 798b9d0 commit 177a6f5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,6 +2545,7 @@ static zend_always_inline zend_result _zend_update_type_info(
25452545
* code may assume that operands have at least one type. */
25462546
if (!(t1 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS))
25472547
|| !(t2 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS))
2548+
|| (ssa_op->result_use >= 0 && !(RES_USE_INFO() & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS)))
25482549
|| ((opline->opcode == ZEND_ASSIGN_DIM_OP
25492550
|| opline->opcode == ZEND_ASSIGN_OBJ_OP
25502551
|| opline->opcode == ZEND_ASSIGN_STATIC_PROP_OP

ext/opcache/tests/opt/gh10008.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
--EXTENSIONS--
7+
opcache
8+
--FILE--
9+
<?php
10+
function test()
11+
{
12+
$bool_or_int = true;
13+
while (a()) {
14+
if ($bool_or_int !== true) {
15+
// The following line triggers narrowing during type inference of ZEND_ADD_ARRAY_ELEMENT.
16+
$string_key = "a";
17+
$array = ["bool_or_int" => $bool_or_int, $string_key => 123];
18+
}
19+
20+
$bool_or_int = 0;
21+
}
22+
}
23+
?>
24+
DONE
25+
--EXPECT--
26+
DONE

0 commit comments

Comments
 (0)