Skip to content

Commit

Permalink
Don't disable early binding during preloading script
Browse files Browse the repository at this point in the history
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".
  • Loading branch information
nikic committed Nov 3, 2020
1 parent b009573 commit 54668a4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions ext/opcache/tests/preload_early_binding.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
var_dump(new X);
class X {}
18 changes: 18 additions & 0 deletions ext/opcache/tests/preload_early_binding.phpt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 54668a4

Please sign in to comment.