]> granicus.if.org Git - php/commitdiff
Preloading: Prevent autoloading while resolving constants
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 4 Jul 2019 09:05:01 +0000 (11:05 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 4 Jul 2019 09:05:01 +0000 (11:05 +0200)
ext/opcache/ZendAccelerator.c
ext/opcache/tests/preload_012.phpt [new file with mode: 0644]
ext/opcache/tests/preload_const_autoload.inc [new file with mode: 0644]
ext/opcache/tests/preload_const_autoload_2.inc [new file with mode: 0644]

index e41ef6725ddc13b28e7cda624ebaa8ce7fd0203b..c94c668c9a6413734e4f129a4ca4ec6a55f29624 100644 (file)
@@ -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 (file)
index 0000000..0883064
--- /dev/null
@@ -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--
+<?php require_once('skipif.inc'); ?>
+--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 (file)
index 0000000..b9634de
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+
+spl_autoload_register(function($class) {
+    var_dump($class);
+    new Abc;
+});
+opcache_compile_file('preload_const_autoload_2.inc');
diff --git a/ext/opcache/tests/preload_const_autoload_2.inc b/ext/opcache/tests/preload_const_autoload_2.inc
new file mode 100644 (file)
index 0000000..9367902
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+class Test {
+    const C = Foo::BAR;
+}