【问题标题】:Cannot redeclare a function previously declared [duplicate]无法重新声明先前声明的函数[重复]
【发布时间】:2013-05-02 03:37:13
【问题描述】:

在我的站点中安装一个脚本后,出现错误:

Fatal error: Cannot redeclare ae_detect_ie() (previously declared in /home/xdesign/public_html/Powerful/config.php:24) in /home/xdesign/public_html/Powerful/config.php on line 29

这是行:

function ae_detect_ie()
{
    if (isset($_SERVER['HTTP_USER_AGENT']) && 
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
        return true;
    else
        return false;
}

我不明白我做错了什么!

网站:http://fbswapes.com

相同的脚本正在另一个主机上运行。

【问题讨论】:

  • 检查this & this out.
  • ! function_exists() 包装它作为一个快速而肮脏的黑客?
  • 或者使用include_once() 来防止两次加载你的配置文件。
  • 这给了我错误.. 解析错误:语法错误,第 22 行 /home/xdesign/public_html/Powerful/config.php 中的意外 T_FUNCTION
  • 这通常发生在您尝试定义已定义的函数时。使用 include_once

标签: php mysql function redeclare


【解决方案1】:

您已经声明了两次函数。示例:

Global.Fun.php

<?php

      function Do_Something (){
       echo "This Does Something";
      }
?>

Index.php

<?php
   include "Global.Fun.php";
   function Do_Something($Arg){
    echo "Argument Supplied".$Arg;
   }
?>

注意,我已经两次声明了同一个函数,一次在我的global.fun.php 页面中,另一次在index.php 页面中..

如果您对当前设置的功能有疑问:

if (function_exists('Do_Something')){
   echo "Function Exists"; 
}else{
   echo "Function Not Found, This name Can be used!";
}

【讨论】:

  • Done new si working,但我有这个错误:警告:mysql_fetch_array() [function.mysql-fetch-array]:结果类型应该是 MYSQL_NUM、MYSQL_ASSOC 或 MYSQL_BOTH。在 /home/xdesign/public_html/Powerful/header.php 第 885 行 在第 885 行,我有: 885 while ($row = mysql_fetch_array($result, $numass)) { 886 array_push($got, $row);第887章
  • @CindySeoLine 错误是……?
  • 警告:mysql_fetch_array() [function.mysql-fetch-array]:结果类型应该是 MYSQL_NUM、MYSQL_ASSOC 或 MYSQL_BOTH。在 /home/xdesign/public_html/Powerful/header.php 第 885 行中 在第 885 行
  • @CindySeoLine 请将代码发布到您的问题中。
  • while ($row = mysql_fetch_array($result, $numass)) {
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-06-11
  • 2013-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多