Skip to content

Commit df243f1

Browse files
committed
Preloading: Prevent autoloading while resolving constants
1 parent 1fea887 commit df243f1

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3414,6 +3414,7 @@ static zend_bool preload_try_resolve_constants(zend_class_entry *ce)
34143414
zval *val;
34153415

34163416
EG(exception) = (void*)(uintptr_t)-1; /* prevent error reporting */
3417+
CG(in_compilation) = 1; /* prevent autoloading */
34173418
do {
34183419
ok = 1;
34193420
changed = 0;
@@ -3455,6 +3456,7 @@ static zend_bool preload_try_resolve_constants(zend_class_entry *ce)
34553456
}
34563457
} while (changed && !ok);
34573458
EG(exception) = NULL;
3459+
CG(in_compilation) = 0;
34583460

34593461
return ok;
34603462
}

ext/opcache/tests/preload_012.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
No autoloading during constant resolution
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/preload_const_autoload.inc
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
===DONE===
12+
--EXPECTF--
13+
Warning: Can't preload class Test with unresolved initializer for constant C in %s on line %d
14+
===DONE===
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
spl_autoload_register(function($class) {
4+
var_dump($class);
5+
new Abc;
6+
});
7+
opcache_compile_file('preload_const_autoload_2.inc');
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
class Test {
4+
const C = Foo::BAR;
5+
}

0 commit comments

Comments
 (0)