Skip to content

Commit 6893f1f

Browse files
committed
SCCP: Don't perform partial object propagation for typed props
1 parent b2cb6a4 commit 6893f1f

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,18 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
12071207
if (ssa_op->op1_def >= 0
12081208
&& ctx->scdf.ssa->vars[ssa_op->op1_def].escape_state == ESCAPE_STATE_NO_ESCAPE) {
12091209
zval *data = get_op1_value(ctx, opline+1, ssa_op+1);
1210+
zend_ssa_var_info *var_info = &ctx->scdf.ssa->var_info[ssa_op->op1_use];
1211+
1212+
/* Don't try to propagate assignments to (potentially) typed properties. We would
1213+
* need to deal with errors and type conversions first. */
1214+
if (!var_info->ce || (var_info->ce->ce_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
1215+
SET_RESULT_BOT(result);
1216+
SET_RESULT_BOT(op1);
1217+
return;
1218+
}
12101219

12111220
/* If $a in $a->foo=$c is UNDEF, treat it like NULL. There is no warning. */
1212-
if ((ctx->scdf.ssa->var_info[ssa_op->op1_use].type & MAY_BE_ANY) == 0) {
1221+
if ((var_info->type & MAY_BE_ANY) == 0) {
12131222
op1 = &EG(uninitialized_zval);
12141223
}
12151224

ext/opcache/tests/opt/sccp_028.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
SCCP 028: Don't propagate typed properties
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload=
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
13+
class Foo {
14+
public int $bar = 1;
15+
}
16+
function test() {
17+
$foo = new Foo();
18+
$foo->bar = "10";
19+
var_dump($foo->bar);
20+
}
21+
test();
22+
23+
?>
24+
--EXPECT--
25+
int(10)

0 commit comments

Comments
 (0)