|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79349 Unlinked anonymous classes prevent using preloading
Submitted: 2020-03-05 11:00 UTC Modified: 2020-03-17 08:30 UTC
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:1 (25.0%)
From: Assigned: nikic (profile)
Status: Closed Package: opcache
PHP Version: 7.4.3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2020-03-05 11:00 UTC]
Following, commit 20ef51db22c46fd45976eb6d0b780c14022c8873 added a new runtime exception that says:

> Fatal error: Class foo wasn't preloaded

I don't how to deal with this exception. I feel like this is a blocker that prevents using preloading when the preloading strategy is base on composer+autoloading. This hits Symfony.

Would it be possible to have nested anonymous classes be loaded at runtime?
This would allow the autoloader to load their dependencies, thus solving the issue.


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-05 11:02 UTC]
Would it be possible to have nested anonymous classes be loaded at *preload* time?
 [2020-03-05 11:03 UTC]
Can you please share the relevant code in Symfony?
 [2020-03-05 11:09 UTC]
The first affect class is this one:

> $cache = new class($cachePath, $this->debug) extends ConfigCache {

Right now, this anonymous class cannot be linked during preloading because the ConfigCache is not available. Then, at runtime, when the code path is hit, the error occurs.

I wish there would be a way to discover programmatically that the ConfigCache class is required so that it could be loaded.
Apparently, there is one internally, since opcache is able to trigger this warning:
> Can't preload unlinked class class@anonymous: Unknown parent Symfony\Component\Config\ConfigCache

But that's too late for me to do anything about it.
Of course, I could explicitly list ConfigCache for preloading - but this doesn't work in the generic case as it requires ad-hoc knowledge of the codebase.
 [2020-03-05 11:15 UTC]
Of course, using regular class autoloading would work also instead of the current error.
 [2020-03-05 11:19 UTC]
Maybe all missing symbols could trigger the autoloader before linking happens?
 [2020-03-11 15:51 UTC]
The following pull request has been associated:

Patch Name: Fix bug #79349: Unlinked anonymous classes prevent using preloading
On GitHub:
 [2020-03-17 08:30 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-03-17 08:30 UTC]
This ended up getting fixed by
 [2020-12-02 07:51 UTC] alexandrebertrand96 at gmail dot com
I still have this error with the symfony bundle omines/datatables-bundle.

> Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\FatalError: "Error: Anonymous class wasn't preloaded" at /var/www/app/vendor/omines/datatables-bundle/src/Adapter/Doctrine/ORMAdapter.php line 329

It's here:

I'm using PHP 7.4.13
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 10:01:29 2024 UTC