php-debugbar icon indicating copy to clipboard operation
php-debugbar copied to clipboard

ParseError PHP7

Open j-combee opened this issue 9 years ago • 6 comments

In php7 they introduced a new error class, ParseError http://php.net/manual/en/class.parseerror.php. This error type conflicts with the ExceptionsCollector::addException(Exception $e);

I have fixed this myself with adding a instanceof check like this:

...

namespace DebugBar\DataCollector;

use Exception;

/**
 * Collects info about exceptions
 */
class ExceptionsCollector extends DataCollector implements Renderable
{
    protected $exceptions = array();
    protected $chainExceptions = false;

    /**
     * Adds an exception to be profiled in the debug bar
     *
     * @param Exception $e
     */
    public function addException(Exception $e)
    {
        $this->exceptions[] = $e;
        $previousError = $e->getPrevious();
        if ($previousError instanceof Exception) {
            if ($this->chainExceptions && $previous = $e->getPrevious()) {
                $this->addException($previous);
            }
        }
    }

...

I put this in a issue and not in a push request since i do not know if there are more new classes that should be considered or if this fix is a correct fix for this issue.

j-combee avatar Apr 05 '16 11:04 j-combee

I've just run into this issue myself. As all exceptions and errors in PHP 7 inherit from the Throwable class, I changed the signatures of addException(Exception $e) and formatExceptionData(Exception $e) to addException(Throwable $e) and formatExceptionData(Throwable $e), which works correctly in the scenarios I've tested, however it obviously isn't particularly clean as the existing code refers to Exceptions everywhere and more importantly won't work on PHP 5.x.

Your change also fixes the issue for me.

rossbearman avatar Apr 05 '16 18:04 rossbearman

Any update on this? Is there any plans to support php7 or should this project be considered abandoned? If I work on a PR will it be accepted?

Thanks

jamiehd avatar Jun 08 '16 09:06 jamiehd

@jamiehd I think pull requests are monitored and the code is updated occasionally; please make the change because I'd need it, hahaha

marceux avatar Jun 09 '16 00:06 marceux

Yes, I think you could probably remove the type hint and just add phpdocs, right? I will accept PR's :)

barryvdh avatar Jun 09 '16 05:06 barryvdh

Any plans for a release with support for PHP 7?

JCMais avatar Aug 15 '16 18:08 JCMais

Following the conversation in #279:

I feel like adding an error with the addException method, as the message will appear in the "Exceptions" tab on the debug bar, besides the addThrowable should be the best idea.

Maybe removing the PHP typehint and checking the instance in runtime to maintain compatibility with PHP 5 and support the Throwable interface if defined would be a good idea?

devnix avatar Jan 16 '19 10:01 devnix