require_once () or die() not working

后端 未结 3 431
慢半拍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:16

    or has a higher precedence than require/require_once. Therefore php evaluates

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

    before passing the result to require_once. Or takes two boolean operands. ('abc.php') evaluates to true therefore the whole expression is true and

    require_once true;
    

    is invoked. require_once takes a string, bool(true)->string => 1 =>

    Failed opening required '1'
    You don't need the or die(...) there. If the file can't be read require_once will stop the php instance anyway.

提交回复
热议问题