Skip to content

Commit d41cacd

Browse files
committed
Fix skipped lazy init on primed SIMPLE_WRITE
Fixes GH-17998
1 parent 6004063 commit d41cacd

File tree

3 files changed

+290
-185
lines changed

3 files changed

+290
-185
lines changed

Zend/tests/lazy_objects/gh17998.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
GH-17998: Skipped lazy init on primed SIMPLE_WRITE
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $prop {
8+
set => $value;
9+
}
10+
}
11+
12+
$nonLazy = new C;
13+
14+
$lazy = (new ReflectionClass(C::class))->newLazyProxy(function () {
15+
echo "init\n";
16+
return new C;
17+
});
18+
19+
function foo(C $c) {
20+
$c->prop = 1;
21+
var_dump($c->prop);
22+
}
23+
24+
foo($nonLazy);
25+
foo($lazy);
26+
27+
?>
28+
--EXPECT--
29+
int(1)
30+
init
31+
int(1)

Zend/zend_vm_def.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,11 +2529,13 @@ ZEND_VM_C_LABEL(fast_assign_obj):
25292529
if (ZEND_IS_PROPERTY_HOOK_SIMPLE_WRITE(prop_offset)) {
25302530
zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2);
25312531
property_val = OBJ_PROP(zobj, prop_info->offset);
2532-
if (ZEND_TYPE_IS_SET(prop_info->type)) {
2533-
value = zend_assign_to_typed_prop(prop_info, property_val, value, &garbage EXECUTE_DATA_CC);
2534-
ZEND_VM_C_GOTO(free_and_exit_assign_obj);
2535-
} else {
2536-
ZEND_VM_C_GOTO(fast_assign_obj);
2532+
if (Z_TYPE_P(property_val) != IS_UNDEF) {
2533+
if (ZEND_TYPE_IS_SET(prop_info->type)) {
2534+
value = zend_assign_to_typed_prop(prop_info, property_val, value, &garbage EXECUTE_DATA_CC);
2535+
ZEND_VM_C_GOTO(free_and_exit_assign_obj);
2536+
} else {
2537+
ZEND_VM_C_GOTO(fast_assign_obj);
2538+
}
25372539
}
25382540
}
25392541
/* Fall through to write_property for hooks. */

0 commit comments

Comments
 (0)