3 ms·
`spl_autoload_register()` is awesome. This is how we implement it: spl_autoload_register(function ($class_name) { require(dirname(dirname(__FILE__)
by nodesocket 14y ago
`spl_autoload_register()` is awesome. This is how we implement it:
spl_autoload_register(function ($class_name) {
require(dirname(dirname(__FILE__)) . "/classes/" . $class_name . ".php");
});
Protip here is `dirname(__FILE__)`
- jasonlotito 14y agoSee __DIR__ if >= 5.3
- ChiperSoft 14y agoWhich, since he's using an anonymous function, he would be.
- nodesocket 14y agoIndeed, slightly cleaner I suppose: spl_autoload_register(function($class_name) { require(dirname(__DIR__) . "/classes/" . $class_name . ".php"); });