|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #22342 the behaviour of require(..) or die(..); is non-intuitive
Submitted: 2003-02-20 18:14 UTC Modified: 2003-02-22 20:58 UTC
From: peter-phpbug at dataloss dot nl Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 4.3.1 OS: Linux
Private report: No CVE-ID: None
 [2003-02-20 18:14 UTC] peter-phpbug at dataloss dot nl
If one would use a line similar to

require("include/xhtml11.php") or die("argh!");

php will fail stating it cannot open "1".

The more intuitive result can be obtained by doing

(require("include/xhtml11.php")) or die("argh!");

I know that require or die is wrong, since require is not a function. However, due to the way precedence (apparently) works with require, the result is non-intuitive and confusing (I am assuming php is evaluating '(..) or die(..)' to 'true', which is 1).


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-02-21 04:51 UTC]
require() dies with fatal error if file is not found..

 [2003-02-21 05:17 UTC]
dup. of #15438

operator precedence problem: or is evaluated before require

i have to confess that the sample doesn't make sense for require, but it is at least a documentation problem for include:

  include("somefile") or die(...);


  (include("somefile")) or die(...);

works as expected

IMHO the WTF factor here is rather big ... :(
 [2003-02-22 20:58 UTC]
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments
to the existing bug instead.

Thank you for your interest in PHP.

Please add your comments to bug #15438

(hartmut, use the quickfix for these.. :)

PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC