Skip to content

Commit c353f17

Browse files
committed
Fix inference for compound object op on dim
1 parent 32af676 commit c353f17

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

ext/opcache/Optimizer/zend_inference.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3185,6 +3185,9 @@ static int zend_update_type_info(const zend_op_array *op_array,
31853185
case ZEND_FETCH_DIM_W:
31863186
case ZEND_FETCH_DIM_RW:
31873187
case ZEND_FETCH_DIM_FUNC_ARG:
3188+
case ZEND_ASSIGN_DIM:
3189+
tmp |= MAY_BE_ARRAY | MAY_BE_ARRAY_OF_ARRAY;
3190+
break;
31883191
case ZEND_ASSIGN_ADD:
31893192
case ZEND_ASSIGN_SUB:
31903193
case ZEND_ASSIGN_MUL:
@@ -3197,8 +3200,11 @@ static int zend_update_type_info(const zend_op_array *op_array,
31973200
case ZEND_ASSIGN_BW_AND:
31983201
case ZEND_ASSIGN_BW_XOR:
31993202
case ZEND_ASSIGN_POW:
3200-
case ZEND_ASSIGN_DIM:
3201-
tmp |= MAY_BE_ARRAY | MAY_BE_ARRAY_OF_ARRAY;
3203+
if (op_array->opcodes[j].extended_value == ZEND_ASSIGN_DIM) {
3204+
tmp |= MAY_BE_ARRAY | MAY_BE_ARRAY_OF_ARRAY;
3205+
} else if (op_array->opcodes[j].extended_value == ZEND_ASSIGN_OBJ) {
3206+
tmp |= MAY_BE_ARRAY_OF_OBJECT;
3207+
}
32023208
break;
32033209
case ZEND_FETCH_OBJ_W:
32043210
case ZEND_FETCH_OBJ_RW:
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Type inference for $ary[$idx]->prop +=
3+
--FILE--
4+
<?php
5+
6+
function test() {
7+
$ary = [];
8+
$ary[0]->y += 2;
9+
var_dump(is_object($ary[0]));
10+
}
11+
test();
12+
13+
?>
14+
--EXPECTF--
15+
Notice: Undefined offset: 0 in %s on line %d
16+
17+
Warning: Creating default object from empty value in %s on line %d
18+
19+
Notice: Undefined property: stdClass::$y in %s on line %d
20+
bool(true)

0 commit comments

Comments
 (0)