Skip to content

rayblair06/PSR4-Autoloader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

🚀 PSR4 - Autoloader 🚀

Autoloading is a commonly used mechanism that automatically loads classes and/or files into memory when they are needed, without having to explicitly include them within each file. In the context of PHP, Composer uses this technique instead of typically using require or include statements to manually load each class before the class is used. Composer can generate a list of mappings defined in composer.json and autoload third party dependencies without much requirement from the user.

Outside of Composer, it is possible to write your own autoloader function so that PHP automatically calls classes that haven't been loaded yet. The spl_autoload_register() function allows you to register one or more autoloaders.

Some of the benefits of autoloading are:

  • Simplicity
  • Efficiency
  • Maintainability

Although writing your own autoloader can be fun and is a great learning experience, it is always better to use tried and tested methods such as Composer's autoloader when building applications that may go into production.

Resources: https://www.php-fig.org/psr/psr-4/ https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md

About

An example of a PSR4 compliant autoloader

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages