Skip to content

Commit bd44c56

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Added test Fix type inference for assign to string offset with invalid index.
2 parents bb5047a + 8a5c681 commit bd44c56

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2690,7 +2690,7 @@ static zend_always_inline zend_result _zend_update_type_info(
26902690
if (ssa_op->result_def >= 0) {
26912691
tmp = 0;
26922692
if (t1 & MAY_BE_STRING) {
2693-
tmp |= MAY_BE_STRING;
2693+
tmp |= MAY_BE_STRING | MAY_BE_NULL;
26942694
}
26952695
if (t1 & (MAY_BE_ARRAY|MAY_BE_FALSE|MAY_BE_NULL|MAY_BE_UNDEF)) {
26962696
tmp |= (OP1_DATA_INFO() & (MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF));
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
JIT ASSIGN_DIM: 006
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
function foo($s) {
11+
$s = "123";
12+
for($i = 0; $i < 5; $i++) {
13+
$x = $s[-5] = "x";
14+
}
15+
var_dump($x);
16+
}
17+
foo("123");
18+
?>
19+
--EXPECTF--
20+
Warning: Illegal string offset -5 in %sassign_dim_006.php on line 5
21+
22+
Warning: Illegal string offset -5 in %sassign_dim_006.php on line 5
23+
24+
Warning: Illegal string offset -5 in %sassign_dim_006.php on line 5
25+
26+
Warning: Illegal string offset -5 in %sassign_dim_006.php on line 5
27+
28+
Warning: Illegal string offset -5 in %sassign_dim_006.php on line 5
29+
NULL

0 commit comments

Comments
 (0)