require_once () or die() not working

后端 未结 3 420
慢半拍i
慢半拍i 2020-12-01 16:49

Does anyone know why my require_once () or die(); is not working. It\'s always shown the Fatal error instead of the error message that I key in into the die(). See below for

3条回答
  •  北海茫月
    2020-12-01 17:30

    When evaluating:

    require_once ('abc.php') or die("oops");
    

    PHP evaluates 'OR die("oops")' first for some reason. to force PHP to evaluate the "require_once ('abc.php')" encolse it in brackets.

    (require_once ('abc.php')) OR die("oops");
    

    However, if "require" fails, PHP stops processing so use "include" instead (see https://stackoverflow.com/a/2418514/1704651). Also, the @ symbol before include_once supresses the error message from MySQL so only the "oops" is output.

    (@include_once ('abc.php')) OR die("oops");
    

    Works as expected.

    Source: My own frustration and https://bugs.php.net/bug.php?id=22342

提交回复
热议问题