Skip to content

Commit 3d216fe

Browse files
committed
Fix unsound SCCP for partial objects with hooks
Fixes GH-21231
1 parent ede7c67 commit 3d216fe

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

Zend/Optimizer/sccp.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,8 +989,14 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
989989
/* Don't try to propagate assignments to (potentially) typed properties. We would
990990
* need to deal with errors and type conversions first. */
991991
// TODO: Distinguish dynamic and declared property assignments here?
992-
if (!var_info->ce || (var_info->ce->ce_flags & ZEND_ACC_HAS_TYPE_HINTS) ||
993-
!(var_info->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)) {
992+
// FIXME: With dynamic property warnings and hooks this has
993+
// become decreasingly useful. Maybe partial objects should just
994+
// be removed.
995+
if (!var_info->ce
996+
|| var_info->is_instanceof
997+
|| (var_info->ce->ce_flags & ZEND_ACC_HAS_TYPE_HINTS)
998+
|| !(var_info->ce->ce_flags & ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES)
999+
|| (var_info->ce->num_hooked_props)) {
9941000
SET_RESULT_BOT(result);
9951001
SET_RESULT_BOT(op1);
9961002
return;

ext/opcache/tests/gh21231.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-21231: Unsound SCCP for partial objects with hooks
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
--FILE--
9+
<?php
10+
11+
#[AllowDynamicProperties]
12+
class Foo {
13+
public $prop { get => 43; set => $value; }
14+
}
15+
16+
function test() {
17+
$obj = new Foo;
18+
$obj->prop = 42;
19+
return $obj->prop;
20+
}
21+
22+
var_dump(test());
23+
24+
?>
25+
--EXPECT--
26+
int(43)

0 commit comments

Comments
 (0)