Skip to content

Commit ef80dcb

Browse files
committed
Fix GH-8074: Wrong type inference of range() result
If either the first or second operand of `range()` may be a string, we must not exclude the possibility that the result may be an array of longs. Closes GH-8131.
1 parent 3198b87 commit ef80dcb

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ PHP NEWS
1919
- MySQLnd:
2020
. Fixed bug GH-8058 (NULL pointer dereference in mysqlnd package). (Kamil Tekiela)
2121

22+
- OPcache:
23+
. Fixed bug GH-8074 (Wrong type inference of range() result). (cmb)
24+
2225
- Zlib:
2326
. Fixed bug GH-7953 (ob_clean() only does not set Content-Encoding). (cmb)
2427

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static uint32_t zend_range_info(const zend_call_info *call_info, const zend_ssa
7878
|| (t3 & (MAY_BE_DOUBLE|MAY_BE_STRING))) {
7979
tmp |= MAY_BE_ARRAY_OF_DOUBLE;
8080
}
81-
if ((t1 & (MAY_BE_ANY-(MAY_BE_STRING|MAY_BE_DOUBLE))) && (t2 & (MAY_BE_ANY-(MAY_BE_STRING|MAY_BE_DOUBLE)))) {
81+
if ((t1 & (MAY_BE_ANY-MAY_BE_DOUBLE)) && (t2 & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
8282
if ((t3 & MAY_BE_ANY) != MAY_BE_DOUBLE) {
8383
tmp |= MAY_BE_ARRAY_OF_LONG;
8484
}

ext/opcache/tests/opt/gh8074.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-8074 (Wrong type inference of range() result)
3+
--FILE--
4+
<?php
5+
function test() {
6+
$array = range(1, "2");
7+
8+
foreach ($array as $i) {
9+
var_dump($i + 1);
10+
}
11+
}
12+
13+
test();
14+
?>
15+
--EXPECT--
16+
int(2)
17+
int(3)

0 commit comments

Comments
 (0)