Pre-Release Software
While updating my PHP 7 talk “What to Expect When You’re Expecting: PHP 7” for the DutchPHP Conference 2 weeks ago I noticed a small but significant change to the new Engine Exceptions feature in the newly release alpha 2.
Prior to alpha 2 and as per the Engine Exceptions RFC the exception hierarchy looked like this:
BaseException (abstract)
├── Exception extends BaseException
├── ErrorException extends Exception
└── RuntimeException extends Exception
└── EngineException extends BaseException
├── TypeException extends EngineException
├── ParseException extends EngineException
└── AssertionError extends EngineException
The primary reason for doing this was to ensure two things:
- That
\EngineException
‘s didn’t get caught in pre-.7.0 catch-all blocks (i.e.catch (\Exception $e) { }
to preserve backwards compatible behavior (fatal erroring appropriately - That it was possible to build new catch-all blocks for all both old and new exceptions using
catch \BaseException $e) { }
However, for alpha2 this hierarchy changed. Engine Exceptions lost their “Exception” suffix, and became \Error
and and \*Error
exceptions, and the abstract \BaseException
class was changed to a \Throwable
interface. This makes the new exception hierarchy look like this:
Throwable interface
├── Exception implements Throwable
├── ErrorException extends Exception
└── RuntimeException extends Exception
└── Error implements Throwable
├── TypeError extends Error
├── ParseError extends Error
└── AssertionError extends Error
With these changes, you still cannot create your own exception hierarchy as you cannot implement \Throwable
, you must still extend from \Exception
or \Error
exceptions (or their children), however you can extend \Throwable
and (while still extending \Exception
or \Error
) implement that new interface.
Personally, I prefer this hierarchy, but, as with any pre-release software: everything is subject to change!
Edit:
As pointed out to me on Twitter, there is an RFC for this change: Throwable interface RFC