Skip to content

Commit

Permalink
Fix dynamic function definition in preload script
Browse files Browse the repository at this point in the history
We should use normal function renaming if the function is declared
during preloading itself, rather than afterwards.

This fixes a regression introduced by
68f80be.
  • Loading branch information
nikic committed Nov 4, 2020
1 parent 4e68c53 commit e0d6c3f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,8 @@ ZEND_API int do_bind_function(zval *lcname) /* {{{ */
return FAILURE;
}
function = (zend_function*)Z_PTR_P(zv);
if (UNEXPECTED(function->common.fn_flags & ZEND_ACC_PRELOADED)) {
if (UNEXPECTED(function->common.fn_flags & ZEND_ACC_PRELOADED)
&& !(CG(compiler_options) & ZEND_COMPILE_PRELOAD)) {
zv = zend_hash_add(EG(function_table), Z_STR_P(lcname), zv);
} else {
zv = zend_hash_set_bucket_key(EG(function_table), (Bucket*)zv, Z_STR_P(lcname));
Expand Down
4 changes: 4 additions & 0 deletions ext/opcache/tests/preload_dynamic_function.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
if (1) {
function f() {}
}
18 changes: 18 additions & 0 deletions ext/opcache/tests/preload_dynamic_function.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
Defining a dynamic function inside the preload script
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload={PWD}/preload_dynamic_function.inc
--SKIPIF--
<?php
require_once('skipif.inc');
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php
var_dump(function_exists("f"));
?>
--EXPECT--
bool(true)

0 comments on commit e0d6c3f

Please sign in to comment.