asplode icon indicating copy to clipboard operation
asplode copied to clipboard

PHP7 implications

Open ezzatron opened this issue 10 years ago • 0 comments

PHP7 brings with it significant changes to error handling:

  • Most errors are now thrown objects of type Error.
  • Error objects are a separate hierarchy to Exception 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 that Error cannot be extended either. Error can be extended without issue.
  • When using the polyfill, catching ErrorException would also catch Error, but this would not be the case under PHP7.

ezzatron avatar Aug 14 '15 04:08 ezzatron