Skip to content

Commit 838746b

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix inference for assignment of known object to reference
2 parents 3de0ccf + 3fdb1aa commit 838746b

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2809,7 +2809,11 @@ static zend_always_inline zend_result _zend_update_type_info(
28092809
tmp |= MAY_BE_DOUBLE;
28102810
}
28112811
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
2812-
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->op1_def);
2812+
if (tmp & MAY_BE_REF) {
2813+
UPDATE_SSA_OBJ_TYPE(NULL, 0, ssa_op->op1_def);
2814+
} else {
2815+
COPY_SSA_OBJ_TYPE(ssa_op->op2_use, ssa_op->op1_def);
2816+
}
28132817
}
28142818
if (ssa_op->result_def >= 0) {
28152819
if (tmp & MAY_BE_REF) {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
Assigning an object of known type to a reference variable
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public int $x = 42;
8+
}
9+
10+
function test() {
11+
$r =& $o;
12+
$o = new Test;
13+
$r = new stdClass;
14+
$r->x = 3.141;
15+
var_dump(is_float($o->x));
16+
}
17+
test();
18+
19+
?>
20+
--EXPECT--
21+
bool(true)

0 commit comments

Comments
 (0)