Skip to content

Commit 89fa775

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix type inference
2 parents 2495459 + 84c1e99 commit 89fa775

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3253,7 +3253,12 @@ static zend_always_inline zend_result _zend_update_type_info(
32533253
tmp |= t1 & (MAY_BE_RC1|MAY_BE_RCN);
32543254
}
32553255
if (opline->op2_type == IS_UNUSED) {
3256-
key_type |= MAY_BE_HASH_ONLY(t1) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
3256+
if (t1 & (MAY_BE_UNDEF|MAY_BE_NULL)) {
3257+
key_type |= MAY_BE_ARRAY_PACKED;
3258+
}
3259+
if (t1 & MAY_BE_ARRAY) {
3260+
key_type |= MAY_BE_HASH_ONLY(t1) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
3261+
}
32573262
} else {
32583263
if (t2 & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
32593264
key_type |= MAY_BE_HASH_ONLY(t1) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Type inference 007: Incorrect array key type inference
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
function y() {
10+
for(;;) {
11+
s($array[]);
12+
$array = array(""=>"");
13+
}
14+
}
15+
?>
16+
DONE
17+
--EXPECT--
18+
DONE

0 commit comments

Comments
 (0)