Skip to content

Commit 8206eb1

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix preloaded constant erroneously propagated to file-cached script
2 parents ee1e5f2 + ec5a1e0 commit 8206eb1

File tree

5 files changed

+59
-0
lines changed

5 files changed

+59
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.5
44

5+
- Opcache:
6+
. Fixed bug GH-21052 (Preloaded constant erroneously propagated to file-cached
7+
script). (ilutov)
58

69
12 Mar 2026, PHP 8.5.4
710

Zend/Optimizer/zend_optimizer.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,9 @@ static bool zend_optimizer_ignore_class(zval *ce_zv, zend_string *filename)
779779
zend_class_entry *ce = Z_PTR_P(ce_zv);
780780

781781
if (ce->ce_flags & ZEND_ACC_PRELOADED) {
782+
if (CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE) {
783+
return true;
784+
}
782785
Bucket *ce_bucket = (Bucket*)((uintptr_t)ce_zv - XtOffsetOf(Bucket, val));
783786
size_t offset = ce_bucket - EG(class_table)->arData;
784787
if (offset < EG(persistent_classes_count)) {
@@ -797,6 +800,9 @@ static bool zend_optimizer_ignore_function(zval *fbc_zv, zend_string *filename)
797800
return false;
798801
} else if (fbc->type == ZEND_USER_FUNCTION) {
799802
if (fbc->op_array.fn_flags & ZEND_ACC_PRELOADED) {
803+
if (CG(compiler_options) & ZEND_COMPILE_WITH_FILE_CACHE) {
804+
return true;
805+
}
800806
Bucket *fbc_bucket = (Bucket*)((uintptr_t)fbc_zv - XtOffsetOf(Bucket, val));
801807
size_t offset = fbc_bucket - EG(function_table)->arData;
802808
if (offset < EG(persistent_functions_count)) {

ext/opcache/tests/gh21052.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
GH-21052: Preloaded constant erroneously propagated to file-cached script
3+
--CREDITS--
4+
Grummfy
5+
--EXTENSIONS--
6+
opcache
7+
--INI--
8+
opcache.enable=1
9+
opcache.enable_cli=1
10+
opcache.file_cache="{TMP}"
11+
opcache.preload={PWD}/gh21052_a.inc
12+
--SKIPIF--
13+
<?php
14+
if (PHP_OS_FAMILY == 'Windows') die('skip Preloading is not supported on Windows');
15+
?>
16+
--FILE--
17+
<?php
18+
require __DIR__ . '/gh21052_b.inc';
19+
?>
20+
--EXPECT--
21+
array(1) {
22+
[0]=>
23+
string(3) "foo"
24+
}
25+
array(1) {
26+
[0]=>
27+
string(3) "foo"
28+
}
29+
array(1) {
30+
[0]=>
31+
string(3) "foo"
32+
}

ext/opcache/tests/gh21052_a.inc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
class A {
4+
const C = ['foo'];
5+
6+
public static function test() {
7+
return ['foo'];
8+
}
9+
}
10+
11+
function test() {
12+
return ['foo'];
13+
}

ext/opcache/tests/gh21052_b.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
var_dump(A::C);
4+
var_dump(A::test());
5+
var_dump(test());

0 commit comments

Comments
 (0)