PHP - Spl_autoload_register
hi
i have some questions about spl_autoload_register when the first param is null. eg. spl_autoload_register(null, false); the manul describe" If no parameter is provided, then the default implementation of spl_autoload() will be registered." now why the follow can't run <?php spl_autoload_register(NULL, false); spl_autoload_extensions('.class.php, .php'); $demo2 = new Demo2();//Demo2.class.php is exist ?> the fllow can run <?php spl_autoload_extensions('.class.php, .php'); spl_autoload('Demo2'); $demo2 = new Demo2(); ?> so , what's the meaning of spl_autoload_register(null, false)? anyone can give me some examples, thanks. Similar TutorialsHi,
I've just found that __autoload function is no longer the thing to use when creating an object from your class. Well thanks a lot!!! Now we have this spl_autoload_register AND spl_autoload. All the manuals I've read I am still lost... just a simple example would be great!!!
I mostly if not always name my classes with the first letter capitalized.
I typically use enable autoloading as follows. I don't know when I started converting the class name to under-case. As such, however, I need to make the filenames undercase.
Is this the correct approach?
spl_autoload_register(function ($class) { $class=strtolower($class); if(file_exists(__DIR__.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.$class.'.php')) { require_once __DIR__.DIRECTORY_SEPARATOR.'classes'.DIRECTORY_SEPARATOR.$class.'.php'; } }); |