Skip to content

Commit 91b3b58

Browse files
authored
Do not resolve constants on non-linked class during preloading (#9975)
Fixes GH-9968
1 parent ce57221 commit 91b3b58

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

ext/opcache/ZendAccelerator.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3975,7 +3975,7 @@ static void preload_link(void)
39753975
if (ce->type == ZEND_INTERNAL_CLASS) {
39763976
break;
39773977
}
3978-
if (!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
3978+
if ((ce->ce_flags & ZEND_ACC_LINKED) && !(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
39793979
if (!(ce->ce_flags & ZEND_ACC_TRAIT)) { /* don't update traits */
39803980
CG(in_compilation) = 1; /* prevent autoloading */
39813981
if (preload_try_resolve_constants(ce)) {

ext/opcache/tests/gh9968-1.inc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
opcache_compile_file('ext/opcache/tests/gh9968-2.inc');

ext/opcache/tests/gh9968-2.inc

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
class Root1_Constant_Definer
4+
{
5+
const CONSTANT = 'value';
6+
}
7+
8+
class Root1_Constant_Empty
9+
{
10+
}
11+
12+
class Root1_Constant_Referencer extends Root2_Empty_Empty
13+
{
14+
protected $propertyReferencingAnExternalConstant = Root1_Constant_Definer::CONSTANT;
15+
}

ext/opcache/tests/gh9968.phpt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
GH-9968: Preload crash on non-linked class
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.preload={PWD}/gh9968-1.inc
8+
--EXTENSIONS--
9+
opcache
10+
--SKIPIF--
11+
<?php
12+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
13+
?>
14+
--FILE--
15+
<?php
16+
17+
new Root1_Constant_Referencer();
18+
19+
?>
20+
==DONE==
21+
--EXPECTF--
22+
Warning: Can't preload unlinked class Root1_Constant_Referencer: Unknown parent Root2_Empty_Empty in %s on line %d
23+
24+
Fatal error: Uncaught Error: Class "Root1_Constant_Referencer" not found in %s:%d
25+
Stack trace:
26+
#0 {main}
27+
thrown in %s on line %d

0 commit comments

Comments
 (0)