PHP 类的自动载入有两种方法,__autoload() 和 spl_autoload_register() ,就是在PHP代码中new一个类的时候,会自动触发,将类的类名包括命名空间作为参数传进入方法里,在方法里可根据命名空间和类名准确找到类文件,从而require或者inlcude进来。菜鸟一枚,作为备忘

<?php
function auto($class){
//$class = A\B\E;
/** 命名空间的自动载入 **/
$class_path = explode("\\",$class);
$file = __DIR__ . '/' ;
foreach($class_path as $c){
$file .= $c . '/';
}
$file = rtrim($file,"/");
$file .= '.php';
var_dump($file);exit;
}
spl_autoload_register('auto');
use A\B\E;
$e = new E();
echo 'hi';
/*******输出*******/
string(32) "/www/test_php_autoload/A/B/E.php"

最新文章

  1. SSDB 主从配置
  2. AndroidUI优化工具——HierarchyViewer
  3. CentOS 6.5下源码安装MySQL 5.6
  4. [iOS UI进阶 - 2.0] 彩票Demo v1.0
  5. Linux shell 脚本攻略之批量重命名
  6. 切换加上延迟加载js代码
  7. 如何使用event 10049分析定位library cache lock and library cache pin
  8. Aforge.net 一个专门为开发者和研究者基于C#框架设计
  9. vi编辑器常见命令的使用
  10. 【小程序】微信小程序实现各种特效实例
  11. Redis环境搭建
  12. response 输出中文数据 文件下载
  13. Spring的声明式事务管理&lt;tx:advice/&gt;
  14. eclipse 如何安装freemaker ftl 插件
  15. 检测cpu、主板、内存
  16. 前端框架之Vue(2)-模板语法
  17. Git-管理和撤销修改
  18. Git创建分支/GIT提交分支
  19. Suse系统中不使用SFTP的话,还可以使用lrzsz。
  20. FineUI 选中多行获取行ID

热门文章

  1. Android+openCV 动态人脸检测
  2. AtCoder Grand Contest 027 (AGC017) D - Modulo Matrix 构造
  3. There is no getter for property named &#39;XXX&#39; in &#39;class java.lang.String&#39;解决方法
  4. sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding=&#39;utf8&#39;) #改变标准输出的默认编码
  5. Wxpython入门
  6. url传参过程中文字需编码、解码使用
  7. Centos6.5部署vsftpd+mysql认证
  8. 【自动化测试】robot framwork的一点小发现
  9. maven deploy Return code is: 400, ReasonPhrase: Bad Request.
  10. aspose 生成word 简单的文档操作