Skip to content
Closed
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
6 changes: 6 additions & 0 deletions Zend/Optimizer/zend_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,9 @@ static bool zend_optimizer_ignore_class(zval *ce_zv, zend_string *filename)
zend_class_entry *ce = Z_PTR_P(ce_zv);

if (ce->ce_flags & ZEND_ACC_PRELOADED) {
if (CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE) {
return true;
}
Bucket *ce_bucket = (Bucket*)((uintptr_t)ce_zv - XtOffsetOf(Bucket, val));
size_t offset = ce_bucket - EG(class_table)->arData;
if (offset < EG(persistent_classes_count)) {
Expand All @@ -817,6 +820,9 @@ static bool zend_optimizer_ignore_function(zval *fbc_zv, zend_string *filename)
return false;
} else if (fbc->type == ZEND_USER_FUNCTION) {
if (fbc->op_array.fn_flags & ZEND_ACC_PRELOADED) {
if (CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE) {
return true;
}
Comment on lines +823 to +825
Copy link
Member

@dstogov dstogov Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for this change?
It's not covered by test(s) and it's not related to constants propagation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using the term constant propagation in the loose sense. It's function inlining in this case that causes the issue. I expanded the test to cover this case as well.

Bucket *fbc_bucket = (Bucket*)((uintptr_t)fbc_zv - XtOffsetOf(Bucket, val));
size_t offset = fbc_bucket - EG(function_table)->arData;
if (offset < EG(persistent_functions_count)) {
Expand Down
32 changes: 32 additions & 0 deletions ext/opcache/tests/gh21052.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--TEST--
GH-21052: Preloaded constant propagated to file-cached script
--CREDITS--
Grummfy
--EXTENSIONS--
opcache
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_cache="{TMP}"
opcache.preload={PWD}/gh21052_a.inc
--SKIPIF--
<?php
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
?>
--FILE--
<?php
require __DIR__ . '/gh21052_b.inc';
?>
--EXPECT--
array(1) {
[0]=>
string(3) "foo"
}
array(1) {
[0]=>
string(3) "foo"
}
array(1) {
[0]=>
string(3) "foo"
}
13 changes: 13 additions & 0 deletions ext/opcache/tests/gh21052_a.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

class A {
const C = ['foo'];

public static function test() {
return ['foo'];
}
}

function test() {
return ['foo'];
}
5 changes: 5 additions & 0 deletions ext/opcache/tests/gh21052_b.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

var_dump(A::C);
var_dump(A::test());
var_dump(test());
Loading