View Issue Details

IDProjectCategoryView StatusLast Update
0002116XdebugUncategorizedpublic2022-11-27 20:56
Reporterlordsimal Assigned Toderick  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionnot fixable 
Product Version3.1.5 
Summary0002116: Fatal error: __debuginfo() must return an array with object passed via method parameter
Description

Xdebug throws a Fatal error: __debuginfo() must return an array in when a __debugInfo() throws an exception.

But only when that object is being passed down via a methods argument.

For more details see https://github.com/LordSimal/xdebug-debuginfo-error

TagsNo tags attached.
Operating System
PHP Version8.1.0-8.1.4

Activities

lordsimal

2022-09-07 20:48

reporter   ~0006373

Last edited: 2022-10-02 15:32

Sorry to not explaining the issue directly in here but let me fix that with this note:

This error can only be achieved via at least 2 classes: a Debugger and a ThrowsDebugInfo class

Debugger.php contains one method which provides debugging info for a given object.

    public static function debug(object $toDebug)
    {
        if (method_exists($toDebug, '__debugInfo')) {
            try {
                $toDebug->__debugInfo();
            } catch (\Exception $e) {
                // Do something
            }
        }
    }

And ThrowsDebugInfo just throws an exception inside the __debugInfo() method.

class ThrowsDebugInfo
{
    public function __debugInfo()
    {
        throw new \Exception('from __debugInfo');
    }
}

The weird part is, that doing a try-catch manually over the ThrowsDebugInfo object does NOT throw an error:

        $obj = new \App\ThrowsDebugInfo();
        try {
            $obj->__debugInfo();
        } catch (\Exception $e) {
            // Do something
        }

but doing basically the same via the Debugger class (which contains a try-catch as well) breaks when xdebug is enabled

        $obj = new \App\ThrowsDebugInfo();
        \App\Debugger::debug($obj);

With the following error:

Warning: Uncaught Exception: from __debugInfo in /Users/kevinpfeifer/Documents/CakePHP/xdebug_test/src/ThrowsDebugInfo.php:10

But ONLY when xdebug is enabled. If I unload the xdebug extension then the second code part also works without a problem.

derick

2022-10-02 15:36

administrator   ~0006382

Xdebug can call __debugInfo at any time, during stack frame stringifcation (happens upon every function call), and at other times. On any object. If you decide to throw an exception in a __debugInfo() method, then this might blow up. It is PHP that generates that error. I don't think there is anything to do here on the Xdebug site, and you should "just" not throw exceptions in __debugInfo() calls.

lordsimal

2022-11-27 20:56

reporter   ~0006456

Seems this was fixed with 3.1.6 as can be seen here: https://bugs.xdebug.org/view.php?id=00002100

Issue History

Date Modified Username Field Change
2022-09-03 11:23 lordsimal New Issue
2022-09-07 20:48 lordsimal Note Added: 0006373
2022-10-02 15:32 derick Note Edited: 0006373
2022-10-02 15:36 derick Assigned To => derick
2022-10-02 15:36 derick Status new => resolved
2022-10-02 15:36 derick Resolution open => not fixable
2022-10-02 15:36 derick Note Added: 0006382
2022-11-27 20:56 lordsimal Note Added: 0006456