dsgdfh302506
2014-11-08 09:15
浏览 59
已采纳

spl_autoload_register实例化类

We know that autoloading your classes is saving time and lines of codes, however. I must instantiate that class with $config = new config(); in order to use that loaded class.

spl_autoload_register(function($class) {
    include $class . '.class.php';
});

Is it possible to load all my classes with spl_autoload_register and then instantiate all those classes:

spl_autoload_register(function($class) {
    include $class . '.class.php';
    $class = new $class;
});

图片转代码服务由CSDN问答提供 功能建议

我们知道自动加载类可以节省时间和代码行。 我必须使用 $ config = new config(); 来实例化该类,以便使用该加载的类。

  spl_autoload_register(function($ class)  {
 include $ class。'。class.php'; 
}); 
   
 
 

是否可以使用 spl_autoload_register <加载我的所有类 / code>然后实例化所有这些类:

  spl_autoload_register(function($ class){
 include $ class。'。class.php'; 
 $ class =  new $ class; 
}); 
   
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doulifang5554 2014-11-08 09:43
    已采纳

    That doesn't make any sense since autoload is called whenever you instantiate an object, and not for instantiating new objects.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题