Skip to content

Do not resolve constants on non-linked class during preloading #9975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -3975,7 +3975,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) = 1; /* prevent autoloading */
if (preload_try_resolve_constants(ce)) {
Expand Down
3 changes: 3 additions & 0 deletions ext/opcache/tests/gh9968-1.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

opcache_compile_file('ext/opcache/tests/gh9968-2.inc');
15 changes: 15 additions & 0 deletions ext/opcache/tests/gh9968-2.inc
Original file line number Diff line number Diff line change
@@ -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;
}
27 changes: 27 additions & 0 deletions ext/opcache/tests/gh9968.phpt
Original file line number Diff line number Diff line change
@@ -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