首页建站经验 php类自动加载器实现方法

php类自动加载器实现方法

本文实例讲述了php类自动加载器实现方法。分享给大家供大家参考。具体如下:这里autoload 可兼容以下格式:Cache_File_Jsonclass_xxx.phpxxx.class.phpxxx.phpphp代码如下:funct…

本文实例讲述了php类自动加载器实现方法。分享给大家供大家参考。具体如下:

这里autoload 可兼容以下格式:

Cache_File_Json

class_xxx.php

xxx.class.php

xxx.php

php代码如下:

function __autoload($className){

$dirs=explode('_',$className);

$fileName=array_pop($dirs);

//print_r($dirs);

$filePath=$fileName;

if(is_array($dirs) && (count($dirs) > 0)){

//echo '/n---/n'; print_r($dirs);

$dirPath='';

foreach ($dirs as $dir){

if($dir){

$dirPath.=strtolower($dir).DIRECTORY_SEPARATOR;

}

}

$filePath=$dirPath.$fileName.'.php';

}else {

if( file_exists('class_'.$fileName.'.php')){

$filePath='class_'.$fileName.'.php';

}else {

if( file_exists($fileName.'.class.php')){

$filePath=$fileName.'.class.php';

} else {

$filePath=$fileName.'.php';

}

}

}

//var_dump($filePath);

require $filePath;

}

希望本文所述对大家的php程序设计有所帮助。

本文来自网络,不代表1号站长-站长学院|资讯交流平台立场。转载请注明出处: https://www.1cn.cc/jianzhan/jingyan/18214.html
上一篇php无序树实现方法
下一篇 PHP实现的json类实例
admin

作者: admin

这里可以再内容模板定义一些文字和说明,也可以调用对应作者的简介!或者做一些网站的描述之类的文字或者HTML!

为您推荐

评论列表()

    联系我们

    联系我们

    0898-88888888

    在线咨询: QQ交谈

    邮箱: email@wangzhan.com

    工作时间:周一至周五,9:00-17:30,节假日休息

    关注微信
    微信扫一扫关注我们

    微信扫一扫关注我们

    关注微博
    返回顶部