summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-11-03 16:45:13 +0100
committerNikita Popov <nikita.ppv@gmail.com>2020-11-03 16:45:13 +0100
commit54668a449e2e535f638b6b0bc22c8c3956e534a2 (patch)
treeb77eddd389c9171b70b36c17337785ad9b7bf98e
parentb009573f4e2f085208f583faffc050746d5d363e (diff)
downloadphp-git-54668a449e2e535f638b6b0bc22c8c3956e534a2.tar.gz
Don't disable early binding during preloading script
We should only disable early binding during the opcache_compile_file() calls, not inside the preloading script or anything it includes. The right condition to check for is whether we compile the file without execution, as declaring classes is "execution".
-rw-r--r--Zend/zend_compile.c2
-rw-r--r--ext/opcache/tests/preload_early_binding.inc3
-rw-r--r--ext/opcache/tests/preload_early_binding.phpt18
3 files changed, 22 insertions, 1 deletions
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 0fd9c04330..af137e424d 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -7385,7 +7385,7 @@ void zend_compile_class_decl(znode *result, zend_ast *ast, zend_bool toplevel) /
if (toplevel
/* We currently don't early-bind classes that implement interfaces or use traits */
&& !ce->num_interfaces && !ce->num_traits
- && !(CG(compiler_options) & ZEND_COMPILE_PRELOAD)) {
+ && !(CG(compiler_options) & ZEND_COMPILE_WITHOUT_EXECUTION)) {
if (extends_ast) {
zend_class_entry *parent_ce = zend_lookup_class_ex(
ce->parent_name, NULL, ZEND_FETCH_CLASS_NO_AUTOLOAD);
diff --git a/ext/opcache/tests/preload_early_binding.inc b/ext/opcache/tests/preload_early_binding.inc
new file mode 100644
index 0000000000..0adcd6b6d7
--- /dev/null
+++ b/ext/opcache/tests/preload_early_binding.inc
@@ -0,0 +1,3 @@
+<?php
+var_dump(new X);
+class X {}
diff --git a/ext/opcache/tests/preload_early_binding.phpt b/ext/opcache/tests/preload_early_binding.phpt
new file mode 100644
index 0000000000..0db5ab1418
--- /dev/null
+++ b/ext/opcache/tests/preload_early_binding.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Early binding should work fine inside the preload script
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.optimization_level=-1
+opcache.preload={PWD}/preload_early_binding.inc
+--SKIPIF--
+<?php
+require_once('skipif.inc');
+if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
+?>
+--FILE--
+OK
+--EXPECT--
+object(X)#1 (0) {
+}
+OK