Skip to content

Commit 798b9d0

Browse files
committed
Fixed GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
1 parent 0da1356 commit 798b9d0

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,8 @@ static zend_always_inline int _zend_update_type_info(
25302530
* unreachable code. Propagate the empty result early, so that that the following
25312531
* code may assume that operands have at least one type. */
25322532
if (!(t1 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS))
2533-
|| !(t2 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS))) {
2533+
|| !(t2 & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS))
2534+
|| (ssa_op->result_use >= 0 && !(RES_USE_INFO() & (MAY_BE_ANY|MAY_BE_UNDEF|MAY_BE_CLASS)))) {
25342535
tmp = 0;
25352536
if (ssa_op->result_def >= 0 && !(ssa_var_info[ssa_op->result_def].type & MAY_BE_REF)) {
25362537
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);

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)