I am interested in learning autoloading, but new to PHP.
I am reading the book “PHP in Action” which writes the autoload method like
function __autoload($className) {
include_once __autoloadFilename($className);
}
function __autoloadFilename($className) {
return str_replace('_','/',$className).".php";
}
I want to pack these methods in a class. will it be better to pack them in an abstract class?
Or in normal class and including it in index.php?
How effeciently I can use the autoloading feature?
Thanks
Securing an autoloader, ensure:
includeis pretty much likeeval. For example disallow url inclusion via the php configuration.You can also white-list namespaces and/or classnames that are appropriate for your concrete autoloader.
Create a class as an autoloader, you must not take the static way, you can just assign any callback with
spl_autoload_register, so you can register multiple autoloaders.Some quickly written autoloader class stub: