This repository was archived by the owner on Mar 27, 2019. It is now read-only.
PHP7 implications #16
Open
Description
PHP7 brings with it significant changes to error handling:
- Most errors are now thrown objects of type
Error
. Error
objects are a separate hierarchy toException
objects.- Both errors, and exceptions implement
Throwable
.
As a result, if an application using Asplode wants to handle PHP5 and PHP7 errors simultaneously, it would currently need to do something like this:
try {
// code
} catch (ErrorException $e) {
// handle
} catch (Error $e) {
// handle
}
We could make this simpler, by adding a polyfill for the Error
class and Throwable
interface. This would allow the application to use just one catch statement:
try {
// code
} catch (Error $e) {
// handle
}
The polyfill would basically do the following:
interface Throwable
{
// appropriate methods
}
class Error extends ErrorException implements Throwable
{
}
Then all of Asplode's error exceptions could inherit from Error
.
There are some issues with this idea:
Throwable
cannot be directly implemented in PHP7, it may turn out thatError
cannot be extended either.Error
can be extended without issue.- When using the polyfill, catching
ErrorException
would also catchError
, but this would not be the case under PHP7.