1.2.1654. set_exception_handler() Warning¶
The set_exception_handler() callable function has to be adapted to PHP 7 : Exception
is not the right type, it is now Throwable
.
When in doubt about backward compatibility, just drop the type. Otherwise, use Throwable
.
<?php
// PHP 5.6- type with Exception
class foo { static function bar(\Exception $e) {} }
// PHP 7+ type with Throwable
class foo { static function bar(\Throwable $e) {} }
// PHP 5 and PHP 7 compatible type (note : there is none)
class foo { static function bar($e) {} }
set_exception_handler([Foo::class, 'bar']);
?>
See also Drop the type and Use Throwable type.
1.2.1654.1. Connex PHP features¶
1.2.1654.1.1. Suggestions¶
Change the typehint from Exception to Throwable.
1.2.1654.1.2. Specs¶
Short name |
Php/SetExceptionHandlerPHP7 |
Rulesets |
|
Exakat since |
0.8.4 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Slow (1 hour) |
Changed Behavior |
PHP 7.0 - More |
Precision |
Very high |
Available in |