doubo4336 2013-06-10 22:12
浏览 65

致命错误:无法重新声明[重复]

This question already has an answer here:

I'm using an image management script/module on one of my websites. In an old version of the script i had no problem importing multiple image-galleries on one page but since I upgraded to a newer version I'm getting the following error (i left out the exact path on my server):

Fatal error: Cannot redeclare general_setting() (previously declared in public_html/myfolder/includes.php:16) in public_html/myfolderincludes.php on line 16

I included 2 different galleries and i understand I'm calling the same function twice because of this. The function the fatal error is reffering to is:

function general_setting($arg) {
$row = mysql_fetch_array (mysql_query ('' . 'SELECT SQL_CACHE `value` FROM `settings` WHERE `setting`=\'' . $arg . '\'')) or die(mysql_error());
return $row['value'];

}

Now my question is... How do i change this so it only calls this function once, no matter how many includes of the script i use on the 'gallery-overview' page.

Thank you in advance!

</div>
  • 写回答

1条回答 默认 最新

  • drxdn40242 2013-06-10 22:23
    关注

    You can wrap your function into

    if (!function_exists('general_setting')) {
        function general_setting($arg) {
        }
    }
    

    That's also common practice in popular PHP frameworks.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料