-
-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dumper: use __debugInfo if present by default to export object #135
Conversation
The current master is PHP 5.6+ only, so I think the condition may be removed :) |
Ah, indeed, good point :). I will gladly do that. |
Uses __debugInfo anyone? |
We do, can't speak for anyone else :). |
For aerys we also use it. |
I certainly will when this is merged. |
👎 On using debug info by default. The only real experience with debug info I have is that it used to cause some strange failures / crashes, not sure whether this has been fixed in PHP 7. |
Personally, I'd love to see the support for this. The mentioned php bug is a little problem here, so I can imagine this as a non-default bahavior. Would be great to be able enable/disable this globally. |
I think making objects dump their guts is violation of SRP, in the same way adding a public getter to be able to test the state of object is. Imho the right way to solve this is this nette/nette#1090 (comment) Are there some native classes, that have this method implemented? |
What I would like to use this for can be seen in attached test case. I don't want to expose internals of object, rather conceal them from being dumped somewhere in logs... So I will definitely use |
@fprochazka This is internal functionality, the purpose is for debugging. Such method has nothing to do with SRP. |
@hrach I disagree. But then again, I'm not strongly against this feature. Just wanned to give my two cents and point to an existing and IMHO better way of dumping&debugging object data. @vojtech-dobes password censoring is a good use-case, that can be also solved using custom |
@fprochazka It can, additionally to |
I am really not sure whether it is useful to support __debugInfo, but in the meantime you can emulate it: Dumper::$objectExporters[null] = function ($obj) {
return method_exists($obj, '__debugInfo') ? $obj->__debugInfo() : (array) $obj;
}; |
@dg That's nice - may I ask what's the trick? Why does |
@vojtech-dobes Have you seen 8037533? |
Thanks. I've discovered it today when exploring new release - clear now. |
5dd8d3e
to
5ecd8e7
Compare
This is resurrection of nette/nette#1415.
Tests are added.
I've also added possibility to switch this off with
Dumper::DEBUGINFO => FALSE
. I've chosenTRUE
as default because it feels to me not only as new feature, but rather matching default behavior of PHP.Last point: I've enabled it only for PHP >=5.6 where this magic method is actually supported by PHP.