Skip to content

Commit c8d10a8

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix type inference for INIT_ARRAY with invalid index
2 parents 3859bff + f18bb24 commit c8d10a8

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,9 @@ static zend_always_inline int _zend_update_type_info(
30493049
arr_type = RES_USE_INFO();
30503050
}
30513051
tmp = MAY_BE_RC1|MAY_BE_ARRAY|arr_type;
3052-
if (opline->op1_type != IS_UNUSED) {
3052+
if (opline->op1_type != IS_UNUSED
3053+
&& (opline->op2_type == IS_UNUSED
3054+
|| (t2 & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_RESOURCE|MAY_BE_STRING)))) {
30533055
tmp |= assign_dim_array_result_type(arr_type, t2, t1, opline->op2_type);
30543056
if (opline->extended_value & ZEND_ARRAY_ELEMENT_REF) {
30553057
tmp |= MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Type inference 002: Type inference for INIT_ARRAY with invalid index
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
var_dump([[]=>&$x]);
10+
?>
11+
--EXPECTF--
12+
Fatal error: Uncaught TypeError: Illegal offset type in %sinference_002.php:2
13+
Stack trace:
14+
#0 {main}
15+
thrown in %sinference_002.php on line 2

0 commit comments

Comments
 (0)