Bug #66216 [Ver->Fbk]: Uncaught exception when using set_error_handler
| From: | nikic@php.net | Date: | Wed, 12 Aug 2020 10:44:23 +0000 |
| Subject: | Bug #66216 [Ver->Fbk]: Uncaught exception when using set_error_handler | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228543@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66216&edit=1
ID: 66216
Updated by: nikic@php.net
Reported by: bastiaan at basenlily dot me
Summary: Uncaught exception when using set_error_handler
-Status: Verified
+Status: Feedback
Type: Bug
Package: Scripting Engine problem
Operating System: Any
PHP Version: 5.5.6
Block user comment: N
Private report: N
New Comment:
@cmb's examples work fine as of PHP 7.4. Is there anything else left to do here?
Previous Comments:
------------------------------------------------------------------------
[2016-07-02 12:05:40] cmb@php.net
Related To: Bug #72532
------------------------------------------------------------------------
[2016-07-02 12:03:03] cmb@php.net
I can reproduce the described behavior (as of PHP 5.3.18
respectively 5.4.8), see <https://3v4l.org/U9bu8>.
Interestingly,
silencing the require statement results in no message at all, see
<https://3v4l.org/N42dN>.
------------------------------------------------------------------------
[2015-06-23 11:10:07] theseer@php.net
There seem to be more problems with internally generated errors, as the following testcase
demonstrates:
<?php
set_exception_handler(
function(Exception $e){
echo "-- handler --\n"; var_dump($e); exit(1);
}
);
set_error_handler(
function($severity, $message, $file, $line) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
);
try {
require 'non-existing-file.php';
} catch (\Exception $e) {
echo "-- catch --\n";
var_dump($e); exit(2);
}
Expected result:
Either a "classical" Fatal Error should occur or the warning for the missing file should
be converted into an exception which in turn should be caught by catch() or at least by the global
exception handler.
Actual result:
theseer@nyda ~/Desktop/Error $ php -v
PHP 5.6.10 (cli) (built: Jun 11 2015 08:13:55)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
theseer@nyda ~/Desktop/Error $ php ex2.php
PHP Warning: Uncaught exception 'ErrorException' with message
'require(non-existing-file.php): failed to open stream: No such file or directory' in
/home/theseer/Desktop/Error/ex2.php:13
Stack trace:
#0 /home/theseer/Desktop/Error/ex2.php(13): {closure}(2, 'require(non-exi...',
'/home/theseer/D...', 13, Array)
#1 /home/theseer/Desktop/Error/ex2.php(13): require()
#2 {main}
thrown in /home/theseer/Desktop/Error/ex2.php on line 13
PHP Fatal error: main(): Failed opening required 'non-existing-file.php'
(include_path='.:/usr/share/pear:/usr/share/php') in /home/theseer/Desktop/Error/ex2.php
on line 13
theseer@nyda ~/Desktop/Error $ echo $?
255
The same behavior can be observed with my (relatively old) PHP 7 build:
theseer@nyda ~/Desktop/Error $ php70 -v
PHP 7.0.0-dev (cli) (built: Mar 25 2015 14:40:01)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies
------------------------------------------------------------------------
[2013-12-03 05:15:14] bastiaan at basenlily dot me
Hey laruence,
Sorry for the typo, I was copying the code from my real project. Should have ran it. That said,
corrected the typo and it is still behaving exactly the same:
Fatal error: Uncaught exception 'Exception' with message 'Hello world' in
/Projects/web/test/bug.php on line 3
So far I've tested this on a machine running Mac OS X 10.8.6 and one running Windows (2012
server I think).
------------------------------------------------------------------------
[2013-12-02 08:11:04] laruence@php.net
there is a typo in your example:
should be: echo $e->getMessage();
after fixed that, I can not reproduce the bug you were describing
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=66216
--
Edit this bug report at https://bugs.php.net/bug.php?id=66216&edit=1