Skip to content

Remove dynamic defs from property hooks after preload #19206

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
18 changes: 18 additions & 0 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -4132,6 +4132,24 @@ static void preload_link(void)
preload_remove_declares(op_array);
}
} ZEND_HASH_FOREACH_END();

if (ce->num_hooked_props > 0) {
zend_property_info *info;

ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, info) {
if (info->hooks) {
for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
if (info->hooks[i]) {
op_array = &info->hooks[i]->op_array;
ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION);
if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
preload_remove_declares(op_array);
}
}
}
}
} ZEND_HASH_FOREACH_END();
}
} ZEND_HASH_FOREACH_END();
}

Expand Down
10 changes: 10 additions & 0 deletions ext/opcache/tests/preload_dynamic_def_removal.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ class Test {
echo "dynamic\n";
}
}

public int $hook {
get {
function dynamic_in_hook() {
echo "dynamic in hook\n";
}
return 1;
}
}
}

function func() {
Expand All @@ -16,3 +25,4 @@ function func() {
$test = new Test;
$test->method();
func();
$test->hook;
2 changes: 2 additions & 0 deletions ext/opcache/tests/preload_dynamic_def_removal.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows
<?php
dynamic();
dynamic2();
dynamic_in_hook();
?>
--EXPECT--
dynamic
dynamic2
dynamic in hook