spl_autoload_register[$this, autoload]

只愿长相守 提交于 2019-11-30 05:57:11

 

我的疑问:
spl_autoload_register([$this, 'autoload'])   平时见的都是$this-> ,写成这样[$this, autoload]该怎么理解


可以理解成spl_autoload_register([$this->autoload) 吗

[$this, autoload] 这个数组  
是__aotuload这个魔术方法的变体写法吗

感谢学习群的 Find老师 详细的解答

示例

class test{

  public static function loadprint($class){

    $file = $class . '.class.php';

    if(is_file($file)){

      require_once($file);

    }

  }

}

spl_autoload_register( array('test', 'loadprint') );

//另一种写法:spl_autoload_register( "test::loadprint");

$obj = new PRINTIT();

$obj->doprint();

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!