php自动加载带命名空间类的函数
代码:
<?php/*@desc:自动加载类的函数@param dir 需要注册自动加载的文件夹*/function autoloader($dir){spl_autoload_register(function($name) use ($dir){ $name = str_replace('\\',DIRECTORY_SEPARATOR,$name); require $dir.DIRECTORY_SEPARATOR.$name.'.php';});}
测试:
autoloader('a');use a\config;$config = new config();$config->say();
输出:
hello
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。