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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值