PHP方法不起作用。怎么解决?

时间:2018-12-21 12:27:56

标签: php codeigniter

if(function_exists($this->Common_model->disable_foreign_key_checks()) && function_exists($this->Common_model->increase_size_of_group_concat()) && function_exists($this->Common_model->increase_size_of_concat())){
    echo 'SUCCESS';
}
else{
    echo 'FAIL';
}

任何人都可以帮助我,为什么function_exists无法正常工作?该项目基于CodeIgniter。

2 个答案:

答案 0 :(得分:3)

在此处使用method_exists方法

 if (method_exists($this->Common_model, 'disable_foreign_key_checks')){
     echo 'SUCCESS';
 } else{
      echo 'FAIL';
 }

答案 1 :(得分:0)

看看您的代码,您似乎完全误解了function_exists()的功能以及它作为参数的含义。

function_exists('function_name')如果定义了名为true的函数,则返回'function_name';如果尚未定义,则返回false

您编写的代码正在使用模型的返回值来提供'function_name'字符串。我严重怀疑这些模型方法中的任何一个都会返回函数的名称。

我将对您真正想做的事情大加猜测。我将假设每个模型函数都将返回true或false来指示成功或失败,并且您要测试所有三个成功函数。如果我的猜测正确,那么这就是您要查找的代码。

if($this->Common_model->disable_foreign_key_checks() && 
   $this->Common_model->increase_size_of_group_concat() && 
   $this->Common_model->increase_size_of_concat())
{
   echo 'SUCCESS';
}
else
{
   echo 'FAIL';
}