Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

@vojtech-dobes
Copy link
Contributor

vojtech-dobes commented Feb 11, 2016

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 chosen TRUE 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.

@hrach

This comment has been minimized.

Copy link
Contributor

hrach commented Feb 11, 2016

The current master is PHP 5.6+ only, so I think the condition may be removed :)

@vojtech-dobes

This comment has been minimized.

Copy link
Contributor Author

vojtech-dobes commented Feb 11, 2016

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.

@vojtech-dobes vojtech-dobes changed the title Dumper: use __debugInfo in PHP >=5.6 by default if present Dumper: use __debugInfo if present by default to export object Feb 11, 2016
@dg

This comment has been minimized.

Copy link
Member

dg commented Feb 11, 2016

Uses __debugInfo anyone?

@vojtech-dobes

This comment has been minimized.

Copy link
Contributor Author

vojtech-dobes commented Feb 11, 2016

Uses __debugInfo anyone?

We do, can't speak for anyone else :).

@staabm

This comment has been minimized.

Copy link
Contributor

staabm commented Feb 11, 2016

For aerys we also use it.

@enumag

This comment has been minimized.

Copy link
Contributor

enumag commented Feb 11, 2016

I certainly will when this is merged.

@JanTvrdik

This comment has been minimized.

Copy link
Contributor

JanTvrdik commented Feb 11, 2016

👎 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.

@hrach

This comment has been minimized.

Copy link
Contributor

hrach commented Feb 12, 2016

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.

@fprochazka

This comment has been minimized.

Copy link
Contributor

fprochazka commented Feb 12, 2016

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?

@vojtech-dobes

This comment has been minimized.

Copy link
Contributor Author

vojtech-dobes commented Feb 12, 2016

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 __debugInfo, but it would be nice if Tracy would understand it too and I wouldn't have to write specific code for it.

@hrach

This comment has been minimized.

Copy link
Contributor

hrach commented Feb 12, 2016

@fprochazka This is internal functionality, the purpose is for debugging. Such method has nothing to do with SRP.

@fprochazka

This comment has been minimized.

Copy link
Contributor

fprochazka commented Feb 12, 2016

@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 Tracy\Dumper::$objectExporters handler.

@vojtech-dobes

This comment has been minimized.

Copy link
Contributor Author

vojtech-dobes commented Feb 12, 2016

@fprochazka It can, additionally to __debugInfo :).

@dg

This comment has been minimized.

Copy link
Member

dg commented Feb 19, 2016

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;
};
@vojtech-dobes

This comment has been minimized.

Copy link
Contributor Author

vojtech-dobes commented Feb 19, 2016

@dg That's nice - may I ask what's the trick? Why does NULL match every object?

@JanTvrdik

This comment has been minimized.

Copy link
Contributor

JanTvrdik commented Feb 22, 2016

@vojtech-dobes Have you seen 8037533?

@vojtech-dobes

This comment has been minimized.

Copy link
Contributor Author

vojtech-dobes commented Feb 22, 2016

@vojtech-dobes Have you seen 8037533?

Thanks. I've discovered it today when exploring new release - clear now.

@dg dg force-pushed the nette:master branch from eba308b to 30fb9ea Feb 23, 2016
@dg dg force-pushed the nette:master branch from fba3e9c to e1e204c Mar 22, 2016
@dg dg force-pushed the nette:master branch 4 times, most recently from 5dd8d3e to 5ecd8e7 Apr 21, 2016
@dg dg closed this May 12, 2016
@vojtech-dobes vojtech-dobes deleted the contentking:debuginfo branch Feb 11, 2017
dg added a commit that referenced this pull request Apr 2, 2018
…GINFO option [Closes #135][Closes #282]
dg added a commit that referenced this pull request Apr 2, 2018
…GINFO option [Closes #135][Closes #282]
dg added a commit that referenced this pull request Apr 3, 2018
dg added a commit that referenced this pull request Apr 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.