Change debug_zval_dump to return the dump unaffected by __debugInfo?

php.internals

Net Mo

9 years ago
Hello Internals. Today I'm fighting with some code that I think uses var_dump() and output buffering to create the output for __debugInfo... or something like that - I'm not really interested into finding the cause :P Anyway, It's not the first time I find myself paralyzed by a slightly broken __debugInfo, including with code that I've written myself (I hate that guy). One big problem is that once you have overriden it in a super class, you can't revert __debugInfo back to the php's implementation easily; the following doesn't actually do the same thing: function __debugInfo(){ return (array)$this; } But even better, it would be nice if debug_zval_dump() always returned the debug information unaffected by custom user-defined __debugInfo. This is by the way what HHVM does: https://3v4l.org/OoJkC Thoughts?

Rowan Collins

9 years ago
On 7 February 2017 11:25:53 GMT+00:00, Wes <netmo.php@gmail.com> wrote:
>But even better, it would be nice if debug_zval_dump() always returned >the >debug information unaffected by custom user-defined __debugInfo. This >is by >the way what HHVM does: https://3v4l.org/OoJkC
While it might be a good idea to have a way of suppressing __debugInfo (I think this came up in the RFC discussion when it was added?), I think debug_zval_dump should be deprecated and removed at this point. The main thing it claims to offer over the many other variable dumps is the refcount, but this has never been reliable, and is now completely broken. The example in the manual recommends using call-time pass-by-reference, which was removed in PHP 5.4; and in PHP 7 the nature of references has changed so radically that it's not even clear what the correct output would be. Regards,
-- Rowan Collins [IMSoP]

Derick Rethans

9 years ago
On Tue, 7 Feb 2017, Rowan Collins wrote:
> On 7 February 2017 11:25:53 GMT+00:00, Wes <netmo.php@gmail.com> wrote: > > >But even better, it would be nice if debug_zval_dump() always > >returned the debug information unaffected by custom user-defined > >__debugInfo. This is by the way what HHVM does: > >https://3v4l.org/OoJkC > > While it might be a good idea to have a way of suppressing __debugInfo > (I think this came up in the RFC discussion when it was added?), I > think debug_zval_dump should be deprecated and removed at this point. > > The main thing it claims to offer over the many other variable dumps > is the refcount, but this has never been reliable, and is now > completely broken. The example in the manual recommends using > call-time pass-by-reference, which was removed in PHP 5.4; and in PHP > 7 the nature of references has changed so radically that it's not even > clear what the correct output would be.
It was always silly IMO. The best way to do this is to accept the argument's *name*, instead of the value: https://derickrethans.nl/xdebug-2.3-xdebug-debug-zval.html cheers, Derick
-- https://derickrethans.nl | https://xdebug.org | https://dram.io Like Xdebug? Consider a donation: https://xdebug.org/donate.php twitter: @derickr and @xdebug

Net Mo

9 years ago
Actually, scratch that, I'm an imbecile... function __debugInfo(){ return (array)$this; } ...would work just fine to access the old style dump.... except that it doesn't. Did you notice that (array)$object cast uses __debugInfo? https://3v4l.org/VKbPj

Net Mo

9 years ago
filed a bug https://bugs.php.net/bug.php?id=74117

Marco Pivetta

9 years ago
Seems invalid, see https://3v4l.org/cKaN8 On 17 Feb 2017 8:08 a.m., "Wes" <netmo.php@gmail.com> wrote:

Net Mo

9 years ago
> I'm an imbecile.
It's confirmed. Sorry for the trashy emails and the bug report. Time to go to bed :P