Skip to content

Commit e0d6c3f

Browse files
committed
Fix dynamic function definition in preload script
We should use normal function renaming if the function is declared during preloading itself, rather than afterwards. This fixes a regression introduced by 68f80be.
1 parent 4e68c53 commit e0d6c3f

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Zend/zend_compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,8 @@ ZEND_API int do_bind_function(zval *lcname) /* {{{ */
10501050
return FAILURE;
10511051
}
10521052
function = (zend_function*)Z_PTR_P(zv);
1053-
if (UNEXPECTED(function->common.fn_flags & ZEND_ACC_PRELOADED)) {
1053+
if (UNEXPECTED(function->common.fn_flags & ZEND_ACC_PRELOADED)
1054+
&& !(CG(compiler_options) & ZEND_COMPILE_PRELOAD)) {
10541055
zv = zend_hash_add(EG(function_table), Z_STR_P(lcname), zv);
10551056
} else {
10561057
zv = zend_hash_set_bucket_key(EG(function_table), (Bucket*)zv, Z_STR_P(lcname));
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
if (1) {
3+
function f() {}
4+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Defining a dynamic function inside the preload script
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/preload_dynamic_function.inc
8+
--SKIPIF--
9+
<?php
10+
require_once('skipif.inc');
11+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
12+
?>
13+
--FILE--
14+
<?php
15+
var_dump(function_exists("f"));
16+
?>
17+
--EXPECT--
18+
bool(true)

0 commit comments

Comments
 (0)