xingyu655 发表于 2017-3-20 11:01:31

php中的__autoload()太鸡肋

  用了__autoload(),不但不规范,反而可读性差,直接插上代码:

<?php
define('TYPE',true);
function __autoload($className){
if(strtolower($className)=='t_newsa'){
include_once "model/{$className}_action.php";
}else if(strtolower($className)=='t_typea'){
include_once "model/{$className}_action.php";
}
}
$newsArr=new T_NewsA();
$typeAction=new T_TypeA();
  如果不用__autoload()
  则为:
  <?php
 define('TYPE',true);
 include_once 'model/T_NewsA_action.php';
 include_once 'model/T_TypeA_action.php';
 include_once 'libs/Smarty.class.php';
 $newsArr=new T_NewsA();
 $typeAction=new T_TypeA();
页: [1]
查看完整版本: php中的__autoload()太鸡肋