Skip to content

Commit 59dfaa3

Browse files
committed
Fix type inference of SEND_UNPACK with empty array
An empty array will not be turned into an array of references. This violated the invariant than an array has values iff it has keys.
1 parent d661a75 commit 59dfaa3

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ext/opcache/Optimizer/zend_inference.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2856,8 +2856,10 @@ static int zend_update_type_info(const zend_op_array *op_array,
28562856
tmp = t1;
28572857
if (t1 & MAY_BE_ARRAY) {
28582858
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
2859-
/* SEND_UNPACK may acquire references into the array */
2860-
tmp |= MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
2859+
if (t1 & MAY_BE_ARRAY_OF_ANY) {
2860+
/* SEND_UNPACK may acquire references into the array */
2861+
tmp |= MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF;
2862+
}
28612863
}
28622864
if (t1 & MAY_BE_OBJECT) {
28632865
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Type inference of SEND_UNPACK with empty array
3+
--FILE--
4+
<?php
5+
function test() {
6+
$array = [1, 2, 3];
7+
$values = [];
8+
var_dump(array_push($array, 4, ...$values));
9+
var_dump($array);
10+
}
11+
test();
12+
?>
13+
--EXPECT--
14+
int(4)
15+
array(4) {
16+
[0]=>
17+
int(1)
18+
[1]=>
19+
int(2)
20+
[2]=>
21+
int(3)
22+
[3]=>
23+
int(4)
24+
}

0 commit comments

Comments
 (0)