Skip to content

Opcache breaks autoloading after E_COMPILE_ERROR #8063

Closed
@shira-374

Description

@shira-374

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions