Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 my code:

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

Error message display as below

"Fatal error: controller::require_once() [function.require]: Failed opening required '1' (include_path='....."

instead of the message ("oops") I key in.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
534 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...