Skip to content
This repository was archived by the owner on Mar 27, 2019. It is now read-only.

PHP7 implications #16

Open
Open
@ezzatron

Description

@ezzatron

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions