|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-07-12 10:11 UTC] mfischer@php.net
Description:
------------
A callable set with "set_exception_handler" receives objects which are not of type Exception.
Why is the "Exception" in the example script typehinted?
Why not, the documentation states:
"This handler function needs to accept one parameter, which will be the exception object that was thrown."
Which is not true anymore.
I welcome "Fatal error" being turned into something which is handleable, but this seems like a BC break and IMHO everything which is thrown should be of type \Exception .
Test script:
---------------
<?php
set_exception_handler(
function (Exception $e) {
var_dump('yodo');
}
);
Foo::bar;
Expected result:
----------------
The handler should receive something which is an "Exception", not an "Error" object.
Actual result:
--------------
$ php test.php
Fatal error: Uncaught TypeError: Argument 1 passed to {closure}() must be an instance of Exception, instance of Error given in /vagrant/api.swat.io/test.php:3
Stack trace:
#0 [internal function]: {closure}(Object(Error))
#1 {main}
thrown in /vagrant/api.swat.io/test.php on line 3
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 04:00:01 2025 UTC |
Actually, I am kindof understand this problem. and maybe we should do some improvements. that is, if the exception be throw is not an compatible exception type of exception_handler. then the exception handler should not be called. actually, this problem is also exists in php5, like <?php set_exception_handler( function (ExceptionA $e) { var_dump('yodo'); } ); class exceptionA extends exception{}; throw new Exception("xxx");