We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Why do Phalcon scan in directories even the class is directly "told" to it?

I know that ->registerDirs is slow, because Phalon then needs to iterate through all directories to load a class. But I found out that even I directly register via ->registerClasses, the loading is still slow. (I know because Im using virtualbox, and its slow). BUT if I remove ->registerDirs - voila! Its superfast!



34.6k
Accepted
answer

registerDirs is slow because for every directory registered it tries to stat the file to see if the file is there. My recommendation is using the namespace strategy.



28.2k

thats okay, but I still dont understand why to. Anyway, thanks Master :)

// Register global classes using Loader classes strategy
//This is the fastest method of autoloading
$loader->registerClasses(
    [
        'AAFV\Constants' => $config->application->constantsFile,
        'AAFV\Routes' => $config->application->routesFile,
        'AAFV\ErrorHandler' => $config->application->controllersDir . $config->application->errorHandler
    ]
);