介绍
本篇文章为大家展示了怎么在php项目中自动载入类,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
php类自动载入方法
& lt; php ? class inload {/* * ,,*,类自动载入,不需要由开发者调用 ,,* ,,*,@param string class 美元;类文件 ,,*/private 才能;function 自动装载(,class 美元) {才能 ,,,如果,空(类)) ,,,{ ,,,,,throw new QException(& # 39;加载文件不存在& # 39;。美元类); ,,,} ,,, ,,,{,, ,,,,,require _SPRING_强生# 39;/_Core SpringMap.php& # 39;,,//框架地图 ,,,,,如果(!,file_exists(,源美元(美元类)(& # 39;文件# 39;),),) ,,,,,{ ,,,,,,,throw new QException(& # 39;加载文件不存在& # 39;。美元类); ,,,,,}, ,,,,,require 源美元(美元类)(& # 39;文件# 39;); ,,,} ,,} ,, ,/* * ,,*,注册或取消注册一个自动类载入方法 ,,* ,,*,该方法参考,Zend 框架 ,,* ,,*,@param string class 美元;提供自动载入服务的类 ,,*,@param boolean enabled 美元;启用或禁用该服务 ,,*/private 才能;function  registerAutoload ($ class =, & # 39;翻译# 39;,,,enabled 美元;=,真的) {才能 ,,,if (! function_exists (& # 39; spl_autoload_register& # 39;)) ,,,{ ,,,,,throw new QException (& # 39; spl_autoload 不存在这个PHP的安装& # 39;); ,,,} ,,,if (enabled 美元;===,真的) ,,,{ ,,,,,spl_autoload_register(数组(类,美元,& # 39;自动装载# 39;)); ,,,} ,,, ,,,{ ,,,,,spl_autoload_unregister(数组(类,美元,& # 39;自动装载# 39;)); ,,,} ,,} ,, ,/* * *才能,析构函数 ,*/public 才能;function  __destruct () {才能 ,,,自我:registerAutoload(& # 39;翻译# 39;,,,假); 以前,,}>上述内容就是怎么在php项目中自动载入类,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。
怎么在php项目中自动载入类