View Issue Details
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0001777||Xdebug||Step Debugging||public||2020-04-11 11:25||2021-01-10 20:14|
|Summary||0001777: var_dump ignores __debugInfo()|
I'll begin my report by stating i'm perfectly aware of the 0001662 fix - __debugInfo should not be used for user-defined classes [ https://bugs.xdebug.org/bug_view_page.php?bug_id=00001662 ], 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.
protected $db ;
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']);
|Tags||No tags attached.|
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.