Closed
Description
Description
If an E_COMPILE_ERROR
is raised during autoloading with opcache enabled, it breaks autoloading during the shutdown process in subsequent requests.
Multiple files are required to reproduce this, so I've put them in this gist:
https://gist.github.com/shira-374/d2077e5581ce5ec53c655c7373846147
With opcache enabled, the script works once, then it always fatals twice. Without opcache it always works as expected.
<?php
spl_autoload_register(function (string $name) {
echo "Autoloading: {$name}<br>\n";
require __DIR__ . '/' . $name . '.php';
});
register_shutdown_function(function () {
new Bar(); // this triggers E_COMPILE_ERROR again for BadClass (???)
new Baz();
echo "Finished<br>\n";
});
new BadClass(); // this triggers E_COMPILE_ERROR
Resulted in this output:
Autoloading: BadClass
Autoloading: Foo
Fatal error: Declaration of BadClass::dummy() must be compatible with Foo::dummy(): void in /var/www/html/BadClass.php on line 5
Autoloading: Bar
Fatal error: Declaration of BadClass::dummy() must be compatible with Foo::dummy(): void in /var/www/html/BadClass.php on line 5
But I expected this output instead:
Autoloading: BadClass
Autoloading: Foo
Fatal error: Declaration of BadClass::dummy() must be compatible with Foo::dummy(): void in /var/www/html/BadClass.php on line 5
Autoloading: Bar
Autoloading: Baz
Finished
PHP Version
8.1.2
Operating System
Debian 11.2