Skip to content

Commit ed8ec9d

Browse files
committed
Fixed type inference (ASSIGN_OP with typed reference may cause type conversion)
1 parent df940a6 commit ed8ec9d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

ext/opcache/Optimizer/zend_inference.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2614,6 +2614,10 @@ static zend_always_inline int _zend_update_type_info(
26142614
* results in a null return value. */
26152615
tmp |= MAY_BE_NULL;
26162616
}
2617+
if (tmp & MAY_BE_REF) {
2618+
/* Typed reference may cause auto conversion */
2619+
tmp |= MAY_BE_ANY;
2620+
}
26172621
} else if (opline->opcode == ZEND_ASSIGN_OBJ_OP) {
26182622
/* The return value must also satisfy the property type */
26192623
if (prop_info) {
@@ -2624,6 +2628,11 @@ static zend_always_inline int _zend_update_type_info(
26242628
if (prop_info) {
26252629
tmp &= zend_fetch_prop_type(script, prop_info, NULL);
26262630
}
2631+
} else {
2632+
if (tmp & MAY_BE_REF) {
2633+
/* Typed reference may cause auto conversion */
2634+
tmp |= MAY_BE_ANY;
2635+
}
26272636
}
26282637
tmp &= ~MAY_BE_REF;
26292638
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
JIT ASSIGN_OP: 002
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
class Test {
11+
public ?string $prop = "0";
12+
}
13+
function test() {
14+
$obj = new Test;
15+
$ref =& $obj->prop;
16+
var_dump($ref &= 1);
17+
}
18+
test();
19+
?>
20+
--EXPECT--
21+
string(1) "0"

0 commit comments

Comments
 (0)