From df243f19be8509f36c9a79a2f601bbaeb37762ae Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 4 Jul 2019 11:05:01 +0200 Subject: [PATCH] Preloading: Prevent autoloading while resolving constants --- ext/opcache/ZendAccelerator.c | 2 ++ ext/opcache/tests/preload_012.phpt | 14 ++++++++++++++ ext/opcache/tests/preload_const_autoload.inc | 7 +++++++ ext/opcache/tests/preload_const_autoload_2.inc | 5 +++++ 4 files changed, 28 insertions(+) create mode 100644 ext/opcache/tests/preload_012.phpt create mode 100644 ext/opcache/tests/preload_const_autoload.inc create mode 100644 ext/opcache/tests/preload_const_autoload_2.inc diff --git a/ext/opcache/ZendAccelerator.c b/ext/opcache/ZendAccelerator.c index e41ef6725d..c94c668c9a 100644 --- a/ext/opcache/ZendAccelerator.c +++ b/ext/opcache/ZendAccelerator.c @@ -3414,6 +3414,7 @@ static zend_bool preload_try_resolve_constants(zend_class_entry *ce) zval *val; EG(exception) = (void*)(uintptr_t)-1; /* prevent error reporting */ + CG(in_compilation) = 1; /* prevent autoloading */ do { ok = 1; changed = 0; @@ -3455,6 +3456,7 @@ static zend_bool preload_try_resolve_constants(zend_class_entry *ce) } } while (changed && !ok); EG(exception) = NULL; + CG(in_compilation) = 0; return ok; } diff --git a/ext/opcache/tests/preload_012.phpt b/ext/opcache/tests/preload_012.phpt new file mode 100644 index 0000000000..0883064ff4 --- /dev/null +++ b/ext/opcache/tests/preload_012.phpt @@ -0,0 +1,14 @@ +--TEST-- +No autoloading during constant resolution +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.optimization_level=-1 +opcache.preload={PWD}/preload_const_autoload.inc +--SKIPIF-- + +--FILE-- +===DONE=== +--EXPECTF-- +Warning: Can't preload class Test with unresolved initializer for constant C in %s on line %d +===DONE=== diff --git a/ext/opcache/tests/preload_const_autoload.inc b/ext/opcache/tests/preload_const_autoload.inc new file mode 100644 index 0000000000..b9634de49a --- /dev/null +++ b/ext/opcache/tests/preload_const_autoload.inc @@ -0,0 +1,7 @@ +