You have two more options besides PSR-4 (or PSR-0):
classmap - this scans directories or files for all classes that are contained, and the result is placed in a PHP array into a file. To do this, you must reset the autoloader whenever a scan file is modified.files - these files will be included when you turn on the Composer autoloader.
So, you can either add a file with auto-generated classes, which will be checked using the classmap autoloader, which would load this file the first time ANY of the classes are used there, or you could add it to the autoload files, which will always be included, regardless whether classes are used or not.
If we consider performance, the first alternative is preferable if the number of classes is not large and the amount of code in the classes is small. Having a lot of tiny classes in classmap is probably more overhead than always, just loading them first.
Having a lot of code in these classes, and they are not always used, the amount or memory saved NOT always can be faster.
If in doubt: measure it. And consider splitting classes into separate files and using PSR-4 if this reduces performance too much.
source share