今天更新了smarty到3.0,结果发现项目中的__autoload()不能用了, 

作为一个刚学习PHP的菜鸟新手,搞了半天才明白问题出在它俩的冲突上,郁闷了好几天。后通过查看,Smarty3.0 中的SMARTY2_BC_NOTES文件,得知Smarty3.0跟php的__autoload()有冲突:

——————————————————————————-——-

== Autoloader ==
Smarty 3 does register its own autoloader with spl_autoload_register. If your code has
an existing __autoload function then this function must be explicitly registered on
the __autoload stack. See http://us3.php.net/manual/en/function.spl-autoload-register.php
for further details.

————————————————————————————————

解决办法是使用spl_autoload_register()注册自己的加载类。

现在给出配置前后的代码:

————————————————————————————————————

  1.   if(substr($className, -6)=="Action"){
  2.    include(APP_CLASS_PATH.'Action/'.$className.".class.php");
  3.   }elseif(substr($className, -5)=="Model"){
  4.    include(APP_CLASS_PATH.'Model/'.$className.".class.php");
  5.   }elseif($className=="Smarty"){
  6.    require_once NET_ROOT."Smarty/Smarty.class.php";
  7.   }elseif(substr($className, -6)=="Public"){
  8.  include(APP_CLASS_PATH.'Public/'.$className.".class.php");
      }
  9.  ——————————————————————————————
  10.  
  11. class ClassAutoloader {
  12.  public function __construct() {
  13.   spl_autoload_register(array($this, 'loader'));
  14.  }
  15.  private function loader($className) {
  16.   if(substr($className, -6)=="Action"){
  17.    echo '1';
  18.    include(APP_CLASS_PATH.'Action/'.$className.".class.php");
  19.   }elseif(substr($className, -5)=="Model"){
  20.    echo '2';
  21.    include(APP_CLASS_PATH.'Model/'.$className.".class.php");
  22.   }elseif($className=="Smarty"){
  23.    echo '3';
  24.    require_once NET_ROOT."Smarty/Smarty.class.php";
  25.   }elseif(substr($className, -6)=="Public"){
  26.    echo '4';
  27.    include(APP_CLASS_PATH.'Public/'.$className.".class.php");
  28.   }
  29.  }
  30. }
  31. $autoloader = new ClassAutoloader();

希望能帮助遇到此问题的朋友,让大家少走弯路。