Skip to content

Commit 982c833

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Drop incorrect cache_slot optimization for typed properties
2 parents d618ed0 + ba8bcf3 commit 982c833

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
@@ -2378,18 +2378,7 @@ ZEND_VM_C_LABEL(assign_object):
23782378
zend_property_info *prop_info = (zend_property_info*) CACHED_PTR_EX(cache_slot + 2);
23792379

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

0 commit comments

Comments
 (0)