php.net |  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
Votes:4
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:1 (25.0%)
From: nicolasgrekas@php.net Assigned: nikic (profile)
Status: Closed Package: opcache
PHP Version: 7.4.3 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
31 - 23 = ?
Subscribe to this entry?

 
 [2020-03-05 11:00 UTC] nicolasgrekas@php.net
Description:
------------
Following https://bugs.php.net/78937, 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.


Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-05 11:02 UTC] nicolasgrekas@php.net
Typo:
Would it be possible to have nested anonymous classes be loaded at *preload* time?
 [2020-03-05 11:03 UTC] nikic@php.net
Can you please share the relevant code in Symfony?
 [2020-03-05 11:09 UTC] nicolasgrekas@php.net
The first affect class is this one:
https://github.com/symfony/symfony/blob/7c90c8ba84f24e3d4b62c02eeb8b14ce23eff59f/src/Symfony/Component/HttpKernel/Kernel.php#L459

> $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] nicolasgrekas@php.net
Of course, using regular class autoloading would work also instead of the current error.
 [2020-03-05 11:19 UTC] nicolasgrekas@php.net
Maybe all missing symbols could trigger the autoloader before linking happens?
 [2020-03-11 15:51 UTC] nikic@php.net
The following pull request has been associated:

Patch Name: Fix bug #79349: Unlinked anonymous classes prevent using preloading
On GitHub:  https://github.com/php/php-src/pull/5257
Patch:      https://github.com/php/php-src/pull/5257.patch
 [2020-03-17 08:30 UTC] nikic@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: nikic
 [2020-03-17 08:30 UTC] nikic@php.net
This ended up getting fixed by https://github.com/php/php-src/pull/5260.
 [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: https://github.com/omines/datatables-bundle/blob/5ccdc1283ff1931c8259796447b8e69f48ea5302/src/Adapter/Doctrine/ORMAdapter.php#L329

I'm using PHP 7.4.13
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 20:01:30 2024 UTC