Best Way To Autoload Classes In PHP

Please, if you need to autoload classes – use the namespaces and class names conventions with SPL autoload, it will save your time for refactoring. And of course, you will need to instantiate every class as an object. Thank you. Like in this thread: PHP Autoloading in Namespaces But if you want a complex workaround, … Read more

How to use spl_autoload() instead of __autoload()

You need to register autoload functions with spl_autoload_register. You need to provide a “callable”. The nicest way of doing this, from 5.3 onwards, is with an anonymous function: spl_autoload_register(function($class) { include ‘classes/’ . $class . ‘.class.php’; }); The principal advantage of this against __autoload is of course that you can call spl_autoload_register multiple times, whereas … Read more