View Issue Details

IDProjectCategoryView StatusLast Update
0002100XdebugUncategorizedpublic2022-11-08 13:13
Reporterflack Assigned Toderick  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version3.1.2 
Fixed in Version3.1.6 
Summary0002100: "Fatal error: debuginfo() must return an array" when Exception is thrown from debugInfo in PHP 8.x
Description

When an exception is thrown from inside a __debugInfo() function, you get a fatal error (in addition to the warning about an uncaught exception), very similar to https://bugs.xdebug.org/view.php?id=1106. Wrapping the code in a try/catch block doesn't help. Without Xdebug (or under PHP 7) it works as expected.

Steps To Reproduce
<?php
class test
{
    public function __debugInfo()
    {
        throw new Exception('X');
        return [];
    }
}

try {
    var_dump(new test);
} catch (Exception $e) {
    echo 'You must be using PHP 7';
}
TagsNo tags attached.
Operating System
PHP Version8.0.10-8.0.19

Activities

flack

2022-06-23 17:30

reporter   ~0006334

P.S.: I also think the error message is wrong. According to

https://wiki.php.net/rfc/magic-methods-signature

The return type for __debugInfo is ?array, so null should also be valid

derick

2022-06-27 09:58

administrator   ~0006336

I get similar results whether Xdebug is enabled or not, on PHP 8.0.21, 8.1.9, and 7.4.29.

Without Xdebug:

$ php -n tests/base/bug02100.phpt

Warning: Uncaught Exception: X in /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt:6
Stack trace:
#0 [internal function]: test->__debugInfo()
#1 /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt(12): var_dump(Object(test))
0000002 {main}
  thrown in /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt on line 6

Fatal error: __debuginfo() must return an array in /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt on line 12

With Xdebug:

$ php tests/base/bug02100.phpt

Warning: Uncaught Exception: X in /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt:6
Stack trace:
#0 [internal function]: test->__debugInfo()
#1 /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt(12): var_dump(Object(test))
0000002 {main}
  thrown in /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt on line 6

Call Stack:
    0.0003     384672   1. {main}() /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt:0
    0.0011     384752   2. var_dump($value = class test {  }) /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt:12

Fatal error: __debuginfo() must return an array in /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt on line 12

Call Stack:
    0.0003     384672   1. {main}() /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt:0
    0.0011     384752   2. var_dump($value = class test {  }) /home/derick/dev/php/derickr-xdebug/tests/base/bug02100.phpt:12

The fatal error comes from PHP itself, so I can't control the output, and I also think it's the right result, as you're not returning an array at all, because you're not returning anything from __debugInfo(), as the Exception short-circuits the return. I don't think there is a bug here.

flack

2022-06-27 12:08

reporter   ~0006337

Last edited: 2022-06-28 15:36

Hm, strange. On Linux, I also see the behavior you describe, but on macOS (PHP from Homebrew) it behaved as I described in the OP. Here is a modified testcase that only fails when XDebug is enabled:

<?php
class test
{
    public function throw(test $object)
    {
        throw new Exception('X');
    }

    public function __debugInfo()
    {
        throw new Exception('X');
        return [];
    }
}

try {
    $t1 = new test;
    $t1->throw(new test);
} catch (Exception $e) {
    echo 'All is well';
}

flack

2022-06-27 20:00

reporter   ~0006338

This might be related: https://github.com/php/php-src/issues/7922

derick

2022-06-29 14:35

administrator   ~0006341

I can reproduce it with your new case, and I have a "hack" PR that disables using __debugInfo() while an exception is already in flight: https://github.com/xdebug/xdebug/pull/846

derick

2022-07-13 18:03

administrator   ~0006345

https://github.com/xdebug/xdebug/pull/846

Issue History

Date Modified Username Field Change
2022-06-23 16:40 flack New Issue
2022-06-23 17:30 flack Note Added: 0006334
2022-06-27 09:58 derick Assigned To => derick
2022-06-27 09:58 derick Status new => feedback
2022-06-27 09:58 derick Note Added: 0006336
2022-06-27 12:08 flack Note Added: 0006337
2022-06-27 12:08 flack Status feedback => assigned
2022-06-27 20:00 flack Note Added: 0006338
2022-06-28 15:36 derick Note Edited: 0006337
2022-06-29 14:34 derick Steps to Reproduce Updated
2022-06-29 14:35 derick Note Added: 0006341
2022-07-13 18:03 derick Status assigned => closed
2022-07-13 18:03 derick Resolution open => fixed
2022-07-13 18:03 derick Fixed in Version => 3.1dev
2022-07-13 18:03 derick Note Added: 0006345
2022-11-08 13:13 derick Fixed in Version 3.1dev => 3.1.6