Skip to content

Commit 69eb6e0

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix ASSIGN_DIM result inference with typed refs Remove outdated code in ASSIGN_DIM type inference
2 parents 214cd15 + 1bb7ee3 commit 69eb6e0

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,31 +2788,21 @@ static zend_always_inline int _zend_update_type_info(
27882788
if (t1 & MAY_BE_STRING) {
27892789
tmp |= MAY_BE_STRING;
27902790
}
2791-
if (t1 & ((MAY_BE_ANY|MAY_BE_UNDEF) - MAY_BE_STRING)) {
2791+
if (t1 & (MAY_BE_ARRAY|MAY_BE_FALSE|MAY_BE_NULL|MAY_BE_UNDEF)) {
27922792
tmp |= (OP1_DATA_INFO() & (MAY_BE_ANY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_ANY | MAY_BE_ARRAY_OF_REF));
27932793

27942794
if (OP1_DATA_INFO() & MAY_BE_UNDEF) {
27952795
tmp |= MAY_BE_NULL;
27962796
}
2797-
if (opline->op2_type == IS_UNUSED) {
2798-
/* When appending to an array and the LONG_MAX key is already used
2799-
* null will be returned. */
2800-
tmp |= MAY_BE_NULL;
2801-
}
2802-
if (t2 & (MAY_BE_ARRAY | MAY_BE_OBJECT)) {
2803-
/* Arrays and objects cannot be used as keys. */
2804-
tmp |= MAY_BE_NULL;
2805-
}
2806-
if (t1 & (MAY_BE_ANY - (MAY_BE_NULL | MAY_BE_FALSE | MAY_BE_STRING | MAY_BE_ARRAY))) {
2807-
/* undef, null and false are implicitly converted to array, anything else
2808-
* results in a null return value. */
2809-
tmp |= MAY_BE_NULL;
2797+
if (t1 & MAY_BE_ARRAY_OF_REF) {
2798+
/* A scalar type conversion may occur when assigning to a typed reference. */
2799+
tmp |= MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING;
28102800
}
28112801
}
2812-
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
28132802
if (t1 & MAY_BE_OBJECT) {
28142803
tmp |= MAY_BE_REF;
28152804
}
2805+
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
28162806
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
28172807
}
28182808
if ((ssa_op+1)->op1_def >= 0) {
@@ -2917,9 +2907,9 @@ static zend_always_inline int _zend_update_type_info(
29172907
}
29182908
if (ssa_op->result_def >= 0) {
29192909
if (tmp & MAY_BE_REF) {
2920-
/* Assignment to typed reference may change type.
2921-
* Be conservative and don't assume anything. */
2922-
tmp = MAY_BE_RC1|MAY_BE_RCN|MAY_BE_ANY|MAY_BE_ARRAY_KEY_ANY|MAY_BE_ARRAY_OF_ANY|MAY_BE_ARRAY_OF_REF;
2910+
/* A scalar type conversion may occur when assigning to a typed reference. */
2911+
tmp &= ~MAY_BE_REF;
2912+
tmp |= MAY_BE_NULL|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_LONG|MAY_BE_DOUBLE|MAY_BE_STRING|MAY_BE_RC1|MAY_BE_RCN;
29232913
}
29242914
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
29252915
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->result_def);

Zend/tests/assign_typed_ref_result.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,16 @@ function test() {
1111
$ref =& $obj->prop;
1212
var_dump($ref = 0);
1313
}
14+
function test2() {
15+
$obj = new Test;
16+
$ary = [];
17+
$ary[0] =& $obj->prop;
18+
var_dump($ary[0] = 0);
19+
}
1420
test();
21+
test2();
1522

1623
?>
1724
--EXPECT--
1825
string(1) "0"
26+
string(1) "0"

0 commit comments

Comments
 (0)