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)
This commit is contained in:
Arnaud Le Blanc 2022-11-25 14:37:55 +01:00
commit 1cba98ebe9
4 changed files with 46 additions and 1 deletions

View file

@ -3983,7 +3983,7 @@ static void preload_link(void)
if (ce->type == ZEND_INTERNAL_CLASS) {
break;
}
if (!(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
if ((ce->ce_flags & ZEND_ACC_LINKED) && !(ce->ce_flags & ZEND_ACC_CONSTANTS_UPDATED)) {
if (!(ce->ce_flags & ZEND_ACC_TRAIT)) { /* don't update traits */
CG(in_compilation) = true; /* prevent autoloading */
if (preload_try_resolve_constants(ce)) {

View file

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

View file

@ -0,0 +1,15 @@
<?php
class Root1_Constant_Definer
{
const CONSTANT = 'value';
}
class Root1_Constant_Empty
{
}
class Root1_Constant_Referencer extends Root2_Empty_Empty
{
protected $propertyReferencingAnExternalConstant = Root1_Constant_Definer::CONSTANT;
}

View file

@ -0,0 +1,27 @@
--TEST--
GH-9968: Preload crash on non-linked class
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.preload={PWD}/gh9968-1.inc
--EXTENSIONS--
opcache
--SKIPIF--
<?php
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php
new Root1_Constant_Referencer();
?>
==DONE==
--EXPECTF--
Warning: Can't preload unlinked class Root1_Constant_Referencer: Unknown parent Root2_Empty_Empty in %s on line %d
Fatal error: Uncaught Error: Class "Root1_Constant_Referencer" not found in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d