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

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>
dongyong5255
dongyong5255 重命名其中一个功能??
7 年多之前 回复

1个回答



您可以将函数包装到</ p>

  if(!function_exists('general_setting')  )){
function general_setting($ arg){
}
}
</ code> </ pre>

这也是流行的PHP框架中的常见做法。</ p>
</ DIV>

展开原文

原文

You can wrap your function into

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

That's also common practice in popular PHP frameworks.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐