All-in-One Event Calendar by Time.ly Exception/Error problem

We recently ran into a problem with the All-in-One Event Calendar WordPress plugin by Time.ly in regards to PHP 7’s change in exception handling. This is one of those “annoying but probably better in the long run” changes that PHP made in the 7.0 release that broke backwards compatibility. The specific problem can be summed up with this entry:

set_exception_handler() is no longer guaranteed to receive Exception objectshttps://secure.php.net/manual/en/migration70.incompatible.php#migration70.incompatible.error-handling.set-exception-handler

What???

The fix that works for my PHP 7 box that I’m pretty sure is backwards compatible with PHP 5.x is to just remove the type hint of the handle_exception method and then throw a new exception, passing in the old one to retain the stack trace. In version 2.5.16 in the file lib/exception/handler.php on line 19 the old code was:

public function handle_exception( Exception $exception ) {
    if ( defined( 'AI1EC_DEBUG' ) && true === AI1EC_DEBUG ) {

This changes to:

public function handle_exception( $exception ) {
    if( $exception instanceof \Error ) {
        throw new \Exception( 'Exception re-throw', 0, $exception );
    }
    if ( defined( 'AI1EC_DEBUG' ) && true === AI1EC_DEBUG ) {

This code is similar but to what the Whoops library is doing.

This answer posted to support forums here.

  • Thanks so much for sharing! Helped me restore a few sites which got upgraded to PHP7 this week.