Doc #80021 [Opn->Ver]: include/require documentation does not mention warnings for missing files
| From: | requinix@php.net | Date: | Wed, 26 Aug 2020 20:03:52 +0000 |
| Subject: | Doc #80021 [Opn->Ver]: include/require documentation does not mention warnings for missing files | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17816@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80021&edit=1
ID: 80021
Updated by: requinix@php.net
Reported by: rsutman at gmail dot com
-Summary: set_error_handler documentation
+Summary: include/require documentation does not mention
warnings for missing files
-Status: Open
+Status: Verified
Type: Documentation Problem
-Package: Documentation problem
+Package: Scripting Engine problem
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Calling require() will give two messages:
1. A warning that /not/a/file does not exist
2. A fatal error because it could not open the file
Your error handler is catching #1.
Using include() would give:
1. A warning that /not/a/file does not exist
2. A warning that it could not open the file
The docs don't consider #1 because that's a regular warning coming from inside PHP when it
goes looking for files. I think. require() and include() themselves are the ones responsible for #2
and that is what the docs talk about.
Those docs should probably point out that looking for a file that does not exist will raise a
warning, and that it happens before the final fatal/warning is given.
Note that in PHP 8, require() will throw an Error exception instead of using a fatal error.
Previous Comments:
------------------------------------------------------------------------
[2020-08-26 17:45:58] rsutman at gmail dot com
Description:
------------
---
From manual page: https://php.net/function.set-error-handler
---
Regarding:
"The following error types cannot be handled with a user defined function: E_ERROR, E_PARSE,
E_CORE_ERROR, E_CORE_WARNING, E_COMPILE_ERROR, E_COMPILE_WARNING independent of where they were
raised, and most of E_STRICT raised in the file where set_error_handler() is called. "
require (https://www.php.net/manual/en/function.require.php) states "it will also
produce a fatal E_COMPILE_ERROR level error."
But I'm using set_error_handler & my defined function IS handling a failed
require. I found the solution on https://stackoverflow.com/a/14103883/802469
Test script:
---------------
https://stackoverflow.com/a/14103883/802469
Or my version (which should do it)
<?php
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
set_error_handler("exception_error_handler");
require("/not/a/file");
?>
Expected result:
----------------
I think the docs just need to be updated, unless I'm misunderstanding something. I very much
like being able to catch fatal errors
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80021&edit=1