加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 无法在exit()内调用函数

发布时间:2020-12-13 22:44:27 所属栏目:PHP教程 来源:网络整理
导读:在commons.php中定义了一个函数 desktop.php - include commons.php | | |/ include MODULES.'mod.php' 我可以在任何我想要的地方调用我的自定义函数,但不能在if内部的出口内调用.调用函数的代码不会出现: Mod.php: ....$error = mysql_error();if($_ADM[
在commons.php中定义了一个函数

desktop.php -> include commons.php
    |
    |
   |/
    include MODULES.'mod.php'

我可以在任何我想要的地方调用我的自定义函数,但不能在if内部的出口内调用.调用函数的代码不会出现:

Mod.php:

....
$error = mysql_error();

if($_ADM['id_user']==1) {
    if(!empty($error)) {
        $debug = array(
                    'message' => "SQL Error in infography_edit module.",'line'    => '79','error'   => $error,'SQL'     => $SQL
                );
        //exit(myPrint($debug)); //Calling here myPrint does not work
          exit(print_r($debug)); //This works
     }
 }

 $test = array('alex');
 exit(myPrint($debug)); //Calling here myPrint works

....

// The output error: Call to undefined function myPrint()

我只是无法理解为什么上面的代码之外的任何其他地方工作,但不在其中而不在里面再次定义它

UPDATE

这样做,似乎也不起作用:

myPrint($debug);
exit();
// The output error: Call to undefined function myPrint()

UPDATE2

desktop.php主文件:

> require(LIBS.’commons.php’);
>常见的HTML
>包含模块

包含桌面代码的键盘:http://codepad.org/hn8QlHQ9

解决方法

怎么样的解决方法

function my_exit($msg){
   echo $msg;
   exit(1);  //Return code of the script,useful for cli scripts
}

//...
my_exit("Show message");
//...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读