php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #38024 require() raises E_WARNING before E_ERROR
Submitted: 2006-07-06 16:09 UTC Modified: 2009-10-09 22:47 UTC
Votes:3
Avg. Score:2.0 ± 1.4
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: kermode at kermodebear dot org Assigned: mez (profile)
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: Ubuntu Linux
Private report: No CVE-ID: None
 [2006-07-06 16:09 UTC] kermode at kermodebear dot org
Description:
------------
It appears that the require and require_once functions raise an E_WARNING before raising an E_ERROR. This is inconsistent with the documentation which implies that only an E_ERROR is raised when require fails.

"The two constructs are identical in every way except how they handle failure. include() produces a Warning while require()  results in a Fatal Error."

Code below tested with PHP versions 4.4.2 on RedHat Linux and 5.1.4 on Ubuntu Linux. Same result.

Reproduce code:
---------------
function default_error_handler($code, $error, $file, $line) {
   switch ($code) {
   case E_WARNING:
      echo "Warning: $error";
      break;
   default:
      echo "Something Else: $error";
   }
}
set_error_handler('default_error_handler');
require('This file does not exist. At least not here!');


Expected result:
----------------
Fatal error: require(): Failed opening required 'This file does not exist. At least not here!' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/kermode/test.php on line 12

Actual result:
--------------
Warning: require(This file does not exist. At least not here!): failed to open stream: No such file or directory
Fatal error: require(): Failed opening required 'This file does not exist. At least not here!' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/kermode/test.php on line 12

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-07-06 16:56 UTC] judas dot iscariote at gmail dot com
this is the expected behaviour.

first warning comes from PHP internal stuff
and then a fatal error is raised.
 [2007-01-22 01:20 UTC] didou@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2009-09-02 14:08 UTC] mez@php.net
This documentation issue still exists... The current documentation reads:-

require() is identical to include()  except upon failure it will produce a fatal E_ERROR  level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue. 

Should probably be

require() is identical to include()  except upon failure it will *ALSO* produce a fatal E_ERROR  level error. In other words, it will halt the script whereas include() only emits a warning (E_WARNING) which allows the script to continue. 

Obviously, without the emphasis.

Once I get back to a sane environment, I'll see if I can remember how to fix the docs.
 [2009-10-09 22:45 UTC] svn@php.net
Automatic comment from SVN on behalf of mez
Revision: http://svn.php.net/viewvc/?view=revision&revision=289452
Log: Fix wording for require (Closes: #38024)
 [2009-10-09 22:47 UTC] mez@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation
better.
 [2020-02-07 06:10 UTC] phpdocbot@php.net
Automatic comment on behalf of didou
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=af9be65b129f12776167c4b4c2dea628377d8efe
Log: Fix #38024: require also produces an E_WARNING
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 22:01:33 2025 UTC