Skip to content

Commit 423a1e5

Browse files
committed
Fixed GH-8251: Narrowing occurred during type inference of ZEND_FETCH_DIM_W
1 parent 39a813d commit 423a1e5

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3682,9 +3682,7 @@ static zend_always_inline zend_result _zend_update_type_info(
36823682
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
36833683
} else {
36843684
/* invalid key type */
3685-
tmp = (tmp & (MAY_BE_RC1|MAY_BE_RCN|MAY_BE_ARRAY)) |
3686-
(t1 & ~(MAY_BE_RC1|MAY_BE_RCN|MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE));
3687-
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
3685+
return SUCCESS;
36883686
}
36893687
COPY_SSA_OBJ_TYPE(ssa_op->op1_use, ssa_op->op1_def);
36903688
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Type inference 023: FETCH_DIM_W
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
function foo($data): array {
10+
$a = [];
11+
$n = -1;
12+
foreach ($data as $d) {
13+
if ($n >= 0) {
14+
$a[$n]->x = 2;
15+
}
16+
$n++;
17+
$a[$n] = new stdClass();
18+
$a[$n]->x = 1;
19+
}
20+
}
21+
?>
22+
DONE
23+
--EXPECT--
24+
DONE

0 commit comments

Comments
 (0)