How works the php autoload feature ?

Card Puncher Data Processing


You may have a lot of class that you need to load 1)

It's the case when building an object-oriented applications PHP where there is one source file per class definition.

You may write a long list of require/includes at the beginning of each script (one for each class) but this is cumbersome.

You may register a function with the spl_autoload_register() that will be called when a class is not found.

Class exist Method

class-exists second argument permits to control if the autoload registered method are called or not


With composer autoload ps4, ps0, you can also define where your classes are stored and call its autoload method.

require_once './vendor/autoload.php';

use Module\Class\Path\Hello
echo Hello.get();

Discover More
Card Puncher Data Processing
Php - Composer

package manager for php. It manages package on a per-project basis, installing them in a directory (e.g. vendor) inside your project. By default it does not install anything globally. It does however...

Share this page:
Follow us:
Task Runner