斗战圣Q

生命并不在于得到什么,而在于做过什么------------------------------------在路上.o0

smarty3.0和__autoload()冲突


今天更新了一下smarty到3.0,结果发现项目中的__autoload()不能用了,原来是因为smarty改变了autoload的方式。

解决方法如下:

function autoload($className){
    if (file_exists(SITEROOT.'include/module/'.$className.'.class.php'))
    include SITEROOT.'include/module/'.$className.'.class.php';
    else
    die('类'.$className.'文件不存在');
}
spl_autoload_register("autoload");

用上面的方式还可以依顺序同时载入几个autoload方法哦


来源: http://hi.baidu.com/aboc/blog/item/b9130ff4345ce978ddc474c3.html



另有解决办法如下

bimal at sanjaal dot com05-Jun-2011 06:58
When multiple scripts try to use __autoload(), there is a collision.
I experienced it while upgrading the Smarty and my own autoload function.

So, the better way is to avoid __autoload() and use spl_register_autoload() instead. If you have written this already, just rename your function to something like __autoload_my_classes, and in the next, call spl_autoload_register as:

<?php
function __autoload_my_classes($classname)
{
 
# ... your logic to include classes here
}
spl_autoload_register('__autoload_my_classes');
?>

You can assign multiple functions to spl_autoload_register() by calling it repeatedly with different function names. Be sure to limit your every function to include a CLASS file.


from: http://cn2.php.net/manual/en/language.oop5.autoload.php#104282


阅读更多
个人分类: php
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭