Skip to content

Fix skipped lazy init on primed SIMPLE_WRITE #17999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Zend/tests/lazy_objects/gh17998.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
--TEST--
GH-17998: Skipped lazy init on primed SIMPLE_WRITE
--FILE--
<?php

class C {
public $prop {
set => $value;
}
}

$nonLazy = new C;

$lazy = (new ReflectionClass(C::class))->newLazyProxy(function () {
echo "init\n";
return new C;
});

function foo(C $c) {
$c->prop = 1;
var_dump($c->prop);
}

foo($nonLazy);
foo($lazy);

?>
--EXPECT--
int(1)
init
int(1)
18 changes: 9 additions & 9 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -2450,12 +2450,14 @@ ZEND_VM_C_LABEL(assign_object):
void **cache_slot = CACHE_ADDR(opline->extended_value);
uintptr_t prop_offset = (uintptr_t)CACHED_PTR_EX(cache_slot + 1);
zval *property_val;
zend_property_info *prop_info;

if (EXPECTED(IS_VALID_PROPERTY_OFFSET(prop_offset))) {
prop_info = (zend_property_info*) CACHED_PTR_EX(cache_slot + 2);

ZEND_VM_C_LABEL(assign_obj_simple):
property_val = OBJ_PROP(zobj, prop_offset);
if (Z_TYPE_P(property_val) != IS_UNDEF) {
zend_property_info *prop_info = (zend_property_info*) CACHED_PTR_EX(cache_slot + 2);

if (prop_info != NULL) {
value = zend_assign_to_typed_prop(prop_info, property_val, value, &garbage EXECUTE_DATA_CC);
ZEND_VM_C_GOTO(free_and_exit_assign_obj);
Expand Down Expand Up @@ -2527,14 +2529,12 @@ ZEND_VM_C_LABEL(fast_assign_obj):
} else {
ZEND_ASSERT(IS_HOOKED_PROPERTY_OFFSET(prop_offset));
if (ZEND_IS_PROPERTY_HOOK_SIMPLE_WRITE(prop_offset)) {
zend_property_info *prop_info = CACHED_PTR_EX(cache_slot + 2);
property_val = OBJ_PROP(zobj, prop_info->offset);
if (ZEND_TYPE_IS_SET(prop_info->type)) {
value = zend_assign_to_typed_prop(prop_info, property_val, value, &garbage EXECUTE_DATA_CC);
ZEND_VM_C_GOTO(free_and_exit_assign_obj);
} else {
ZEND_VM_C_GOTO(fast_assign_obj);
prop_info = CACHED_PTR_EX(cache_slot + 2);
prop_offset = prop_info->offset;
if (!ZEND_TYPE_IS_SET(prop_info->type)) {
prop_info = NULL;
}
ZEND_VM_C_GOTO(assign_obj_simple);
}
/* Fall through to write_property for hooks. */
}
Expand Down
Loading
Loading