1.2.1643. set_exception_handler() Warning

The set_exception_handler() callable function has to be adapted to PHP 7 : Exception is not the right typehint, it is now Throwable.

When in doubt about backward compatibility, just drop the typehint. Otherwise, use Throwable.

<?php

// PHP 5.6- typehint
class foo { function bar(\Exception $e) {} }

// PHP 7+ typehint
class foo { function bar(Throwable $e) {} }

// PHP 5 and PHP 7 compatible typehint (note : there is none)
class foo { function bar($e) {} }

set_exception_handler(foo);

?>

See also Drop the type and Use Throwable type.

1.2.1643.1. Suggestions

  • Change the typehint from Exception to Throwable.

1.2.1643.2. Specs

Short name

Php/SetExceptionHandlerPHP7

Rulesets

All, Changed Behavior, CompatibilityPHP70

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

Features

error-handler

Available in

Entreprise Edition, Exakat Cloud