Skip to content

Commit 1cba98e

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: [ci skip] NEWS [ci skip] NEWS Do not resolve constants on non-linked class during preloading (#9975)
2 parents d526773 + 772bb62 commit 1cba98e

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
@@ -3983,7 +3983,7 @@ static void preload_link(void)
39833983
if (ce->type == ZEND_INTERNAL_CLASS) {
39843984
break;
39853985
}
3986-
if (!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
3986+
if ((ce->ce_flags & ZEND_ACC_LINKED) && !(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
39873987
if (!(ce->ce_flags & ZEND_ACC_TRAIT)) { /* don't update traits */
39883988
CG(in_compilation) = true; /* prevent autoloading */
39893989
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)