I currently have this
class SPL_Load {
public function __construct() {
spl_autoload_register('self::loader');
}
static public function loader($className) {
$filename = str_replace('\\', '/', $className) . '.php';
$filename = str_replace('MVC/', '', $filename);
if(file_exists($filename)) {
require($filename);
}
}
}
Which is called by
new SPL_Load;
in my index.php file, both classes are declared in the same file - I wonder if there's a way to get it so that I can move this
spl_autoload_register('self::loader');
function into this process to remove the need for the __construct()
method in the SPL_Load class
What I mean is something like this
spl_autoload_register('new SPL_Load::loader');
to replace the SPL_Load construct function and make the reference more efficient in terms of amount of code, although I have no idea if this is even possible/where to begin.
Any ideas would be brilliant thanks guys!
spl_autoload_register(array($this, 'loader'))
在“加载程序”功能中删除静态
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.