|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22775 Fatal error from require() exits with status=0
Submitted: 2003-03-18 20:50 UTC Modified: 2003-03-19 02:23 UTC
From: gk at proliberty dot com Assigned:
Status: Closed Package: CGI/CLI related
PHP Version: 4.3.2RC1 OS: linux RH 7.2; kernel 2.4.18
Private report: No CVE-ID:
 [2003-03-18 20:50 UTC] gk at proliberty dot com
According to the manual, require() differs from include() in that failure to open a file is FATAL in require().

Yet, using sapi/cgi/php or sapi/cli/php, fatal errors from require() exit with status=0 instead of non-zero, as one would expect from a 'fatal' error.

I do not know if this problem is true for ALL fatal errors or not.

Calling exit(1) works correctly however, which provides an awkward, but useful, workaround to this problem:
if (!$success) exit(1);

Here is my test file: /htdocs/common/test/junk/test.php

//the following fixes the problem:
//if (!$success) exit(1);

[root@p3 sapi]# cli/php -f /htdocs/common/test/junk/test.php; echo status="$?";

Warning: main(non_existent_file) []: failed to open stream: No such file or directory in /usr/local/apache/htdocs/common/test/junk/test.php on line 4

Fatal error: main() []: Failed opening required 'non_existent_file' (include_path='.:/usr/local/apache/htdocs/common/php:/usr/local/lib/php') in /usr/local/apache/htdocs/common/test/junk/test.php on line 4
[root@p3 sapi]# cli/php -r 'exit(1);'; echo status="$?";
[root@p3 sapi]#


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-18 21:46 UTC] gk at proliberty dot com
Actually I was mistaken about the workaround:
THERE IS NO WAY TO EXIT CORRECTLY, USING require(); only with include()! Which is contrary to the entire purpose of using require() instead of include().

This does NOT work:
if (!$success) exit(1);

This DOES work:
if (!$success) exit(1);
 [2003-03-19 01:40 UTC] gk at proliberty dot com
improved the title
 [2003-03-19 02:23 UTC]
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at
In case this was a documentation problem, the fix will show up soon at

In case this was a website problem, the change will show
up on the site and on the mirror sites in short time.
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Tue Jan 17 06:01:43 2017 UTC