All-in-One Event Calendar by Exception/Error problem

We recently ran into a problem with the All-in-One Event Calendar WordPress plugin by 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 objects


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.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.