[php-src] Issue #21411: opcache_compile_file() fails to early-bind classes without parents
| From: | rlerdorf | Date: | Wed, 11 Mar 2026 04:50:11 +0000 |
| Subject: | [php-src] Issue #21411: opcache_compile_file() fails to early-bind classes without parents | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-251786@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/21411
Author: rlerdorf
### Description
The following code:
test.inc:
```php
<?php
echo NoParentClass::VALUE . "\n";
class NoParentClass {
const VALUE = "hello";
}
```
Compiled and loaded via opcache file cache:
```php
<?php
// Step 1: Compile into file cache
opcache_compile_file('/path/to/test.inc');
// Step 2: In a separate process, include from file cache
include '/path/to/test.inc';
```
With INI settings:
```
opcache.enable=1
opcache.enable_cli=1
opcache.file_cache=/tmp/cache
opcache.file_cache_only=1
opcache.file_update_protection=0
```
Resulted in this output:
```
Fatal error: Uncaught Error: Class "NoParentClass" not found in /path/to/test.inc:2
Stack trace:
#0 Command line code(1): include()
#1 {main}
thrown in /path/to/test.inc on line 2
```
But I expected this output instead:
```
hello
```
### PHP Version
```plain
This affects versions 8.3+ because https://github.com/php/php-src/commit/0600f513b374969992f86591ad9834a32df319a8,
which implemented delayed early binding for classes without parents, did not take into account that
opcache_compile_file() produces unlinked classes with an empty-string
lc_parent_name, causing zend_accel_do_delayed_early_binding() to skip
early binding for these classes when loading them from cache.
```
### Operating System
_No response_