【问题标题】:Skip function is it's declared already跳过函数是否已经声明
【发布时间】:2011-12-24 11:37:55
【问题描述】:

首先,我使用function_exists 来检查我的函数之前是否已声明但没有帮助。

这是我的代码:

if ( !function_exists('something') ) {
   function something($params) {
       [..]
   }
}

当我进入该函数两次声明的页面时,出现以下错误:Fatal error: Cannot redeclare something() (previously declared in [..])

所以问题是,我如何检查该函数是否已经存在,如果它存在跳过加载它两次?

【问题讨论】:

  • 只需在您的 php 代码中使用 include_oncerequire_once
  • 您是如何将函数声明两次的?如果是因为包含,您应该使用include_once()

标签: php function exists


【解决方案1】:
if( !function_exists('something') ){
    require("something_definer.php");
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    • 2015-08-19
    • 1970-01-01
    • 2014-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多