]> granicus.if.org Git - php/commitdiff
Fix dynamic function definition in preload script
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 4 Nov 2020 09:54:08 +0000 (10:54 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 4 Nov 2020 09:54:08 +0000 (10:54 +0100)
We should use normal function renaming if the function is declared
during preloading itself, rather than afterwards.

This fixes a regression introduced by
68f80be9d1380de731930187250a7ed6b55ae196.

Zend/zend_compile.c
ext/opcache/tests/preload_dynamic_function.inc [new file with mode: 0644]
ext/opcache/tests/preload_dynamic_function.phpt [new file with mode: 0644]

index 810e384177ecdde4270d932d1ed6a756ada17394..df4cd4b2f3feb37b014069c1f044a0b4ed9cbb9f 100644 (file)
@@ -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));
diff --git a/ext/opcache/tests/preload_dynamic_function.inc b/ext/opcache/tests/preload_dynamic_function.inc
new file mode 100644 (file)
index 0000000..3caa959
--- /dev/null
@@ -0,0 +1,4 @@
+<?php
+if (1) {
+    function f() {}
+}
diff --git a/ext/opcache/tests/preload_dynamic_function.phpt b/ext/opcache/tests/preload_dynamic_function.phpt
new file mode 100644 (file)
index 0000000..451a58e
--- /dev/null
@@ -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)