com php-src: Fix dynamic function definition in preload script: Zend/zend_compile.c ext/opcache/tests/preload_dynamic _function.inc
ext/opcache/tests/preload_dynamic_funct ion.phpt
| From: | Nikita Popov | Date: | Wed, 04 Nov 2020 09:54:08 +0000 |
| Subject: | com php-src: Fix dynamic function definition in preload script: Zend/zend_compile.c ext/opcache/tests/preload_dynamic _function.inc ext/opcache/tests/preload_dynamic_funct ion.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-114057@lists.php.net to get a copy of this message | ||
Commit: e0d6c3f7bae2644802f13bd1ae1f49c3d08a8e07
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 4 Nov 2020 10:54:08 +0100
Parents: 4e68c53a210648aa03415f1683ba83d45b67c17c
Branches: PHP-7.4 PHP-8.0 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e0d6c3f7bae2644802f13bd1ae1f49c3d08a8e07
Log:
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
68f80be9d1380de731930187250a7ed6b55ae196.
Changed paths:
M Zend/zend_compile.c
A ext/opcache/tests/preload_dynamic_function.inc
A ext/opcache/tests/preload_dynamic_function.phpt
Diff:
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 810e384177e..df4cd4b2f3f 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -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
index 00000000000..3caa9592b88
--- /dev/null
+++ b/ext/opcache/tests/preload_dynamic_function.inc
@@ -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
index 00000000000..451a58eb343
--- /dev/null
+++ b/ext/opcache/tests/preload_dynamic_function.phpt
@@ -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)