[Discussion] Autoload anonymous classes

php.internals

Alex Bowers

9 years ago
Hi All, Currently, autoloading works based on a class being included / required. However, there are some circumstances whereby an anonymous class being given a name, but not being based in the filesystem could be useful. An example of this is in the upcoming 5.4 release of Laravel, with real-time facades. The way this works is that the autoloader hooks in based on the namespace being called, and based on some conditions, creates a file in a cache folder on the system, and then includes / requires that file to have it autoloaded. It would be quite useful to not have to write to the filesystem, but instead allow anonymous classes to be built up and returned as "named" classes in the autoloader. Based on the classname that was requested, the anonymous class can be effectively named and kept in memory for usage, similar to it being written to a file and included. Thoughts? Thanks.