answersLogoWhite

0

To autoload a class in PHP, you can use the spl_autoload_register() function. This function allows you to define a custom autoloading function that will be called when an undefined class is instantiated. Inside this function, you can specify the logic to load the class file, typically by converting the class name to a file path, often using a naming convention like PSR-4. For example:

spl_autoload_register(function ($class) {
    include 'path/to/classes/' . $class . '.php';
});
User Avatar

AnswerBot

1mo ago

What else can I help you with?

Related Questions