Reply To: How Symfony/Laravel automatically autoload and instantiate required object?

#2551
ayeshrajans
Guest

Autoloading is done by the autoloader function. This is almost always Composer Autoloader, which can handle PSR-4 and PSR-0 naming patterns to find the file by the namespaces class. It also supports flat lists of classes and always-include files list.

Classes are instantiated by configuration of reflection API. DICs like Pimple require explicit configuration with a lambda function to return a class instance. Some DICs support annotations or other configuration approaches. Some containers support autowiring, which uses Reflection to know the types of parameters of the requested class constructor, and recursively resolve them.

More complicated DICs support caching, so the reflection/parsing steps are not required on subsequent requests after the cache is built/warmed up.