Skip to content

Commit 90e6a74

Browse files
committed
Merge branch 'PHP-8.0'
* PHP-8.0: Drop incorrect cache_slot optimization for typed properties
2 parents d0b09a7 + 982c833 commit 90e6a74

File tree

3 files changed

+30
-407
lines changed

3 files changed

+30
-407
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
Demonstrate that cache_slot optimization is illegal due to cache_slot merging
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public int $prop;
8+
9+
public function method() {
10+
// Opcache merges cache slots for both assignments.
11+
$this->prop = 1;
12+
try {
13+
$this->prop = "foobar";
14+
} catch (TypeError $e) {
15+
echo $e->getMessage(), "\n";
16+
}
17+
var_dump($this->prop);
18+
}
19+
}
20+
21+
$test = new Test;
22+
$test->method();
23+
$test->method();
24+
25+
?>
26+
--EXPECT--
27+
Cannot assign string to property Test::$prop of type int
28+
int(1)
29+
Cannot assign string to property Test::$prop of type int
30+
int(1)

Zend/zend_vm_def.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2379,18 +2379,7 @@ ZEND_VM_C_LABEL(assign_object):
23792379
zend_property_info *prop_info = (zend_property_info*) CACHED_PTR_EX(cache_slot + 2);
23802380

23812381
if (UNEXPECTED(prop_info != NULL)) {
2382-
zend_uchar orig_type = IS_UNDEF;
2383-
2384-
if (OP_DATA_TYPE == IS_CONST) {
2385-
orig_type = Z_TYPE_P(value);
2386-
}
2387-
23882382
value = zend_assign_to_typed_prop(prop_info, property_val, value EXECUTE_DATA_CC);
2389-
2390-
/* will remain valid, thus no need to check prop_info in future here */
2391-
if (OP_DATA_TYPE == IS_CONST && Z_TYPE_P(value) == orig_type) {
2392-
CACHE_PTR_EX(cache_slot + 2, NULL);
2393-
}
23942383
ZEND_VM_C_GOTO(free_and_exit_assign_obj);
23952384
} else {
23962385
ZEND_VM_C_LABEL(fast_assign_obj):

0 commit comments

Comments
 (0)