Skip to content

Commit

Permalink
Remove declares inside functions as well
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Aug 2, 2021
1 parent 8356da6 commit 9fe3aab
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 6 additions & 2 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -4062,9 +4062,13 @@ static void preload_link(void)
}
} ZEND_HASH_FOREACH_END();

/* Dynamic defs inside methods need to be removed as well. */
/* Dynamic defs inside functions and methods need to be removed as well. */
zend_op_array *op_array;
ZEND_HASH_FOREACH_PTR_FROM(EG(function_table), op_array, EG(persistent_functions_count)) {
ZEND_ASSERT(op_array->type == ZEND_USER_FUNCTION);
preload_remove_declares(op_array);
} ZEND_HASH_FOREACH_END();
ZEND_HASH_FOREACH_PTR_FROM(EG(class_table), ce, EG(persistent_classes_count)) {
zend_op_array *op_array;
ZEND_HASH_FOREACH_PTR(&ce->function_table, op_array) {
if (op_array->type == ZEND_USER_FUNCTION) {
preload_remove_declares(op_array);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
class Test {
function method() {
function dynamic() {
echo "dynamic";
echo "dynamic\n";
}
}
}

function func() {
function dynamic2() {
echo "dynamic2\n";
}
}

$test = new Test;
$test->method();
func();
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
--TEST--
Preloading dynamic def in method
Preloading dynamic def in method/function
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload={PWD}/preload_dynamic_def_in_method.inc
opcache.preload={PWD}/preload_dynamic_def_removal.inc
--EXTENSIONS--
opcache
--SKIPIF--
Expand All @@ -14,6 +14,8 @@ if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows
--FILE--
<?php
dynamic();
dynamic2();
?>
--EXPECT--
dynamic
dynamic2

0 comments on commit 9fe3aab

Please sign in to comment.