Cannot throw objects that do not implement Throwable¶
Description¶
All classes that are thrown must implement the interfave Throwable. It is possible to catch Throwable
objects, but in fact, it is not possible to implement Throwable
in a class: this is done by extending either Exception
or Error
, which, in turn, implements Throwable.
Example¶
<?php
class X {}
throw new X();
?>
Solutions¶
Make the class extends
\Exception
.Make the class extends
\Error
.Do not throw the class.