View Issue Details

IDProjectCategoryView StatusLast Update
0001777XdebugStep Debuggingpublic2022-04-21 09:13
Reportersargon1404 Assigned Toderick  
Status resolvedResolutionwon't fix 
Product Version2.9.3 
Summary0001777: var_dump ignores __debugInfo()

Greetings gentlemen,

I'll begin my report by stating i'm perfectly aware of the 0001662 fix - __debugInfo should not be used for user-defined classes [ ], however i'll kindly ask you to reconsider this fix, since in my opinion, it does more harm than good when you factor dependency injection into the mix.

Consider for example the below class. If __debugInfo() is ignored, in the output of var_dump i'll see a lot of info i don't want to see, especially since, if using a framework, the Database/Request/other dependencies etc.... will be on the heavy-weight - output wise - size.

At the moment, var_dump is not very helpful, at least for me, except for the most basic cases. Injecting dependencies into a class produces to much 'background noise', preventing me from quickly seeing what the values of the properties i'm interested to see are.

class Foo
    protected $db ;
    protected $request;
    protected $dep1;
    protected $dep2;

    protected $prop1 = '';
    protected $prop2 = '';

    public function __construct(Database $db, Request $request, Dep1 $dep1, Dep2 $dep2)
        $this->db = $db;
        $this->request = $request;
        $this->dep1 = $dep1;
        $this->dep2 = $dep2;

    public function __debugInfo()
        $properties = get_object_vars($this);

        unset($properties['db'], $properties['request'], $properties['dep1'], $properties['dep2']);

        return $properties;
TagsNo tags attached.
Operating System
PHP Version7.4.0-7.4.4



2021-01-10 20:14

reporter   ~0005637

I would like to second sargon1404.

The magic method __debugInfo() was introduced in PHP in order to allow for custom debug information. Especially in user-defined classes.

Having a very different behavior with and without xdebug is very confusing, even more so as the user does initially not understand why __debugInfo() does not work like specified in the PHP specs.

As there seem to be different opinions on the use of debugInfo() in custom classes, I would like to suggest creating a switch in the xdebug configuration to disable debugInfo() for custom classes. The default, in my opinion, should be to have var_dump() work according to the PHP specs.


2021-03-17 09:14

administrator   ~0005735

There is a workaround for this, which is to set a watch called "$this->__debugInfo()". Setting watches is supported by many IDEs.

Because there is a workaround, I am not reverting this to its original state.

If you want to see the "debugInfo" of all object, please ask your IDE producer to include functionality to call this method on every object.

Issue History

Date Modified Username Field Change
2020-04-11 11:25 sargon1404 New Issue
2020-06-20 15:07 derick Status new => acknowledged
2021-01-10 20:14 xleo Note Added: 0005637
2021-03-17 09:14 derick Assigned To => derick
2021-03-17 09:14 derick Status acknowledged => resolved
2021-03-17 09:14 derick Resolution open => won't fix
2021-03-17 09:14 derick Note Added: 0005735
2022-04-21 09:13 derick Description Updated