View Issue Details

IDProjectCategoryView StatusLast Update
0002116XdebugUncategorizedpublic2022-09-07 20:48
Reporterlordsimal Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
Status newResolutionopen 
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

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.

Issue History

Date Modified Username Field Change
2022-09-03 11:23 lordsimal New Issue
2022-09-07 20:48 lordsimal Note Added: 0006373