Skip to content

Commit b734d45

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix type inference for FETCH_DI_UNSET
2 parents f15cfba + bd30eff commit b734d45

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3348,7 +3348,12 @@ static zend_always_inline int _zend_update_type_info(
33483348
ZEND_ASSERT(j < 0 && "There should only be one use");
33493349
}
33503350
}
3351-
if (((tmp & MAY_BE_ARRAY) && (tmp & MAY_BE_ARRAY_KEY_ANY)) || opline->opcode == ZEND_FETCH_DIM_FUNC_ARG) {
3351+
if (((tmp & MAY_BE_ARRAY) && (tmp & MAY_BE_ARRAY_KEY_ANY))
3352+
|| opline->opcode == ZEND_FETCH_DIM_FUNC_ARG
3353+
|| opline->opcode == ZEND_FETCH_DIM_R
3354+
|| opline->opcode == ZEND_FETCH_DIM_IS
3355+
|| opline->opcode == ZEND_FETCH_DIM_UNSET
3356+
|| opline->opcode == ZEND_FETCH_LIST_R) {
33523357
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
33533358
} else {
33543359
/* invalid key type */
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Type inference 012: FETCH_DIM_UNSET
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
function test() {
10+
$closure = function() {return "string";};
11+
unset($x['b'][$closure()]['d']);
12+
$x = $arr;
13+
$arr = ['a' => $closure(), 'b' => [$closure() => []]];
14+
$x = $arr;
15+
unset($x['b'][$closure()]['d']);
16+
$x = $arr;
17+
}
18+
19+
test();
20+
?>
21+
DONE
22+
--EXPECTF--
23+
Warning: Undefined variable $x in %sinference_012.php on line 4
24+
25+
Warning: Undefined variable $arr in %sinference_012.php on line 5
26+
DONE

0 commit comments

Comments
 (0)