1.2.102. Can’t Implement Throwable¶
Classes extending Throwable
can’t be thrown, unless they also extend Exception
. The same applies to interfaces that extends Throwable
.
Although such code lints, PHP throws a Fatal error when executing or including it : Class fooThrowable cannot implement interface `Throwable <https://www.php.net/manual/en/class.`throwable <https://www.php.net/throwable>`_.php>`_, extend `Exception <https://www.php.net/exception>`_ or `Error <https://www.php.net/error>`_ instead
.
<?php
// This is the way to go
class fooException extends \Exception { }
// This is not possible and a lot of work
class fooThrowable implements \throwable { }
?>
See also Throwable, Exception and Error.
1.2.102.2. Connex PHP features¶
1.2.102.2.1. Suggestions¶
Extends the Exception class
Extends the Error class
1.2.102.2.2. Specs¶
Short name |
Exceptions/CantThrow |
Rulesets |
|
Exakat since |
1.3.3 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Note |
This issue may lint but will not run |
Available in |