[RFC] [VOTE] __debugInfo()

php.internals

Sara Golemon

12 years ago
Voting is now open with options which PHP version to release with and how to name it (since some seem to prefer the more compact __debug()) https://wiki.php.net/rfc/debug-info

Joe Watkins

12 years ago
On 02/03/2014 08:06 PM, Sara Golemon wrote:
> Voting is now open with options which PHP version to release with and > how to name it (since some seem to prefer the more compact __debug()) > > https://wiki.php.net/rfc/debug-info >
Can you change debugInfo to debuginfo in source code ... so it's consistent with callstatic / tostring etc ... Cheers Joe

Yasuo Ohgaki

12 years ago
Hi Joe, On Tue, Feb 4, 2014 at 5:16 AM, Joe Watkins <pthreads@pthreads.org> wrote:
> On 02/03/2014 08:06 PM, Sara Golemon wrote: > >> Voting is now open with options which PHP version to release with and >> how to name it (since some seem to prefer the more compact __debug()) >> >> https://wiki.php.net/rfc/debug-info >> >> > Can you change debugInfo to debuginfo in source code ... so it's > consistent with callstatic / tostring etc ...
We should stick to naming rules for new features. Otherwise, we'll have more mess... Legacy names should be cleaned up some day, hopefully... Regards,
-- Yasuo Ohgaki yohgaki@ohgaki.net

chobie

12 years ago
2014-02-04 Sara Golemon <pollita@php.net>:
> Voting is now open with options which PHP version to release with and > how to name it (since some seem to prefer the more compact __debug()) > > https://wiki.php.net/rfc/debug-info > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >
great! I've sometimes thought if I could hide unwanted property in user defined class. btw, how can I make an array which has visibility prefixed key (like \0*\0b) easily? i don't mind current one. but I guess almost php users doesn't know that.

Crypto Compress

12 years ago
Hi! This is a somewhat unexpected BC break in a point release. Why no 6.0 option? class Dog { public function __debugInfo() { return ['Cat']; } } var_dump(new Dog); // Array { "Cat" } Name is a bit ambiguous. This method does not debug anything as in xdebug or phpdbg. It exposes internal "__state". cryptocompress

Yasuo Ohgaki

12 years ago
Hi Crypto, On Tue, Feb 4, 2014 at 6:03 AM, Crypto Compress < cryptocompress@googlemail.com> wrote:
> This is a somewhat unexpected BC break in a point release. Why no 6.0 > option? > class Dog { public function __debugInfo() { return ['Cat']; } } > var_dump(new Dog); // Array { "Cat" } > > Name is a bit ambiguous. This method does not debug anything as in xdebug > or phpdbg. It exposes internal "__state". >
__someMethod() is reserved name for internal use and it is explicitly documented. If it breaks, it's users fault. We cannot cover all of user faults... Regards,
-- Yasuo Ohgaki yohgaki@ohgaki.net

Crypto Compress

12 years ago
Meant output of var_dump is unexpected.

Yasuo Ohgaki

12 years ago
Hi Crypto, On Tue, Feb 4, 2014 at 6:11 AM, Crypto Compress < cryptocompress@googlemail.com> wrote:
> Meant output of var_dump is unexpected.
I don't think output of var_dump() would change. Is it correct, Sara? Regards,
-- Yasuo Ohgaki yohgaki@ohgaki.net

Yasuo Ohgaki

12 years ago
Hi Crypto, On Tue, Feb 4, 2014 at 6:34 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> On Tue, Feb 4, 2014 at 6:11 AM, Crypto Compress < > cryptocompress@googlemail.com> wrote: > >> Meant output of var_dump is unexpected. > > > I don't think output of var_dump() would change. > Is it correct, Sara? >
The sentence may be confusing. __debugInfo() changes var_dump() output. However, existing code will not be affected, since user should have __debugInfo(). Therefore, it cannot be a BC issue. Regards,
-- Yasuo Ohgaki yohgaki@ohgaki.net

Sara Golemon

12 years ago
On Mon, Feb 3, 2014 at 1:55 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> On Tue, Feb 4, 2014 at 6:34 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote: >> I don't think output of var_dump() would change. >> Is it correct, Sara? > > The sentence may be confusing. __debugInfo() changes var_dump() output. > However, existing code will not be affected, since user should have > __debugInfo(). >
Ah, sorry, missed your clarification. Yes, we're on the same page. -Sara

Crypto Compress

12 years ago
Hello Sara, some more questions: 1. Can this hook be bypassed or disabled (global/temporary)? e.g. real_var_dump(), ini setting, some other flag? 2. What will be affected by this hook beside "var_dump"? e.g. xdebug output, var_export, ... 3. How would this behave (segfault?): public function __debugInfo() { var_dump($this); return []; } Thank You! cryptocompress

Tjerk Meesters

12 years ago
On Tue, Feb 4, 2014 at 7:47 PM, Crypto Compress < cryptocompress@googlemail.com> wrote:
> Hello Sara, > > some more questions: > > 1. Can this hook be bypassed or disabled (global/temporary)? > e.g. real_var_dump(), ini setting, some other flag? > > 2. What will be affected by this hook beside "var_dump"? > e.g. xdebug output, var_export, ... > > 3. How would this behave (segfault?): > public function __debugInfo() { var_dump($this); return []; } >
Yeah, there doesn't seem to be any recursion protection, just like: public function __toString() { return (string)$this; }
> > Thank You! > > cryptocompress > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
-- -- Tjerk

Sara Golemon

12 years ago
On Tue, Feb 4, 2014 at 3:47 AM, Crypto Compress <cryptocompress@googlemail.com> wrote:
> 1. Can this hook be bypassed or disabled (global/temporary)? > e.g. real_var_dump(), ini setting, some other flag? >
No. The existing get_debug_info behavior is always active and this RFC just lifts it up to the userspace level. Is there a specific use case for which you'd like that? I suppose you could always do: var_dump((array)$obj); and get the "real" prop info. In practice, an object would use this hook to provide better info, keeping implementation details out of the way (such as current uses in dom, sxe, mysqli, intl, and spl).
> 2. What will be affected by this hook beside "var_dump"? > e.g. xdebug output, var_export, ... >
var_dump() and print_r() are the only current uses of get_debug_info
> 3. How would this behave (segfault?): > public function __debugInfo() { var_dump($this); return []; } >
Badly (most likely timeout or memory limit E_ERROR). Don't do that. -Sara

Sara Golemon

12 years ago
On Mon, Feb 3, 2014 at 1:34 PM, Yasuo Ohgaki <yohgaki@ohgaki.net> wrote:
> I don't think output of var_dump() would change. > Is it correct, Sara? >
The output of var_dump() *would* change. That's the point of the debug info hook. But as you say, it's still not relevant as __ is a reserved namespace. -Sara P.S. 5.6 isn't a point release, it's a minor release. Point releases are updates to the third number, and I agree introducing it in a point release would be a bad idea.

George Bond

12 years ago
On 3 February 2014 21:11, Crypto Compress <cryptocompress@googlemail.com>wrote:
> Meant output of var_dump is unexpected.
But that's not a B/C *break*, because users are explicitly instructed not to write functions beginning with double underscores unless they want magic functionality, and since this is *new* magic functionality *no*correctly-constructed code will contain a function named "__debugInfo()". Any old code which does contain such a function is already explicitly standards-defying, and so does not deserve any B/C maintenance. That's the whole point in reserving the whole namespace of double-underscore-prefixed functions for future magic behaviour. The fact that with this function developers can write *new*weird/broken/counter-intuitive code like you write is certainly valid. But it's not a B/C issue. --G

Crypto Compress

12 years ago
>> Meant output of var_dump is unexpected. > The fact that with this function developers can write > *new*weird/broken/counter-intuitive code like you write is certainly > valid. But it's not a B/C issue. >
Valid point. This can't be BC issue as such code is nonexistent. It will confuse later on.

Stas Malyshev

12 years ago
Hi!
> This is a somewhat unexpected BC break in a point release. Why no 6.0 > option?
Names prefixed with __ are reserved for system use. You should never ever name anything in user code starting with __.
-- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227

Derick Rethans

12 years ago
On Mon, 3 Feb 2014, Crypto Compress wrote:
> This is a somewhat unexpected BC break in a point release. Why no 6.0 option? > class Dog { public function __debugInfo() { return ['Cat']; } } > var_dump(new Dog); // Array { "Cat" }
__ method names are reserved for internals. There is no BC break. cheers, Derick

Crypto Compress

12 years ago
> __ method names are reserved for internals. There is no BC break.
Yes, there is however an expectation break but thats not the Point. May even be useful. Imagine a mock library: Usecase #1: end-user Sees only immediate useful data. No cluttered object graph. Very useful! Usecase #2: new maintainer Hunting bug in mock object. No way to var_dump object internals at all. Wait what?

Johannes Schlueter

12 years ago
On Tue, 2014-02-11 at 19:54 +0100, Crypto Compress wrote:
> > __ method names are reserved for internals. There is no BC break. > > Yes, there is however an expectation break but thats not the Point. May > even be useful. > > Imagine a mock library: > > Usecase #1: end-user > Sees only immediate useful data. No cluttered object graph. Very useful! > > Usecase #2: new maintainer > Hunting bug in mock object. No way to var_dump object internals at all. > Wait what?
This is still no BC break in PHP but probably bad usage. You can still see "the truth" via reflection and by using a proper debugger (like xdebug, I assume) johannes

Crypto Compress

12 years ago
> You can still see "the truth" via reflection and by using a proper debugger (like xdebug, I assume) >
Reflection is mentioned in RFC. Sadly it does not solve the problem. Replaced output is *not* bypassable without external tools (xdebug/phpdbg). If i'am wrong correct me.

Johannes Schlueter

12 years ago
On Tue, 2014-02-11 at 22:05 +0100, Crypto Compress wrote:
> > You can still see "the truth" via reflection and by using a proper debugger (like xdebug, I assume) > > > > Reflection is mentioned in RFC. Sadly it does not solve the problem. > Replaced output is *not* bypassable without external tools > (xdebug/phpdbg). If i'am wrong correct me.
ReflectionObject provides access to an object and its properties. This is not going to change in case this is accepted. It will be extended toe able to *also* provide this debug info, this doesn't affect ReflectionObject::getProperty() etc., though. johannes

Crypto Compress

12 years ago
Am 11.02.2014 22:12, schrieb Johannes Schlüter:
> On Tue, 2014-02-11 at 22:05 +0100, Crypto Compress wrote: >>> You can still see "the truth" via reflection and by using a proper debugger (like xdebug, I assume) >>> >> Reflection is mentioned in RFC. Sadly it does not solve the problem. >> Replaced output is *not* bypassable without external tools >> (xdebug/phpdbg). If i'am wrong correct me. > ReflectionObject provides access to an object and its properties. This > is not going to change in case this is accepted. It will be extended toe > able to *also* provide this debug info, this doesn't affect > ReflectionObject::getProperty() etc., though. > > johannes > >
Sorry! We talk at cross purposes: - reflection is not changed - (array)$this is possible This is currently not needed nor related to var_dump(). This RFC changes var_dump/print_r output without a bypass option. Hacks are needed to get current behavior back. Indeed it may be possible to replace var_dump/print_r with something. This discussion is about this issue.

Johannes Schlueter

12 years ago
On Tue, 2014-02-11 at 22:44 +0100, Crypto Compress wrote:
> Sorry! We talk at cross purposes: > - reflection is not changed > - (array)$this is possible > > This is currently not needed nor related to var_dump(). This RFC changes > var_dump/print_r output without a bypass option. Hacks are needed to get > current behavior back. Indeed it may be possible to replace > var_dump/print_r with something. This discussion is about this issue.
Yes that is the purpose of this RFC and that voters have to decide about: evaluate risk of abuse vs. making unreadable results usable. johannes

Crypto Compress

12 years ago
Good evening, ladies and gentlemen! Solutions to problems created by RFCs are inherent and should not be solved in followup RFCs. The __debugInfo RFC replaces one problem [1] by a subtile other one [2]. Why is it impossible to solve [1] and consequent [2] *within* this RFC? [1] way too big object dumps [2] no reliable way to create object dumps at all Thank you! cryptocompress p.s.: As most of you don't have time to read all the posts, a chronological summary: ---------- 1/3 ---------- Am 05.02.2014 21:54, schrieb Sara Golemon:
> On Wed, Feb 5, 2014 at 12:11 PM, Crypto Compress > <cryptocompress@googlemail.com> wrote: >> It's not easy nor fast to change output of a whole object graph. >> > Oh, I see what you were getting at now. Yeah, that would be onerous > if you found yourself in that position. Might be a good idea to do a > followup RFC to introduce an INI setting. I'm not keen on adding a > new method, that kind of misses the point of the original hook. > > -Sara
---------- 2/3 ---------- Am 11.02.2014 21:23, schrieb Crypto Compress:
> Am 11.02.2014 21:06, schrieb Rowan Collins: >> On 11/02/2014 18:29, Crypto Compress wrote: >>> Imagine a proxy object (orm). >>> >>> Usecase #1: end-user >>> Sees only proxied object. No cluttered object graph. Very useful! >>> >>> Usecase #2: new maintainer >>> Hunting bug in proxy object. No way to dump internals at all. Wait >>> what? >>> >> >> On the other hand, usecase #3: hunting bug in incredibly complex >> object and "can't see the wood for the trees" because object graph >> fills pages of output. >> >> Temporarily (re-)implement __debugInfo() to output a few relevant >> properties, and all becomes much clearer. I could have used this >> earlier today, in fact; I ended up with something like dump( >> array($this->foo, $this->bar, $this->baz) ) > > Yes! I'm convinced this hook is a very useful extension for poor man's > debugger. > Would like to see status quo enhanced, not replaced. > > >> >> There might be merit in a way of viewing the "real" contents of an >> object, I guess, although that doesn't have any meaning for objects >> exposed by extensions anyway, as they can overload in ways user-land >> can only dream of. (Hence SimpleXML being so confusing if you try to >> debug it as though it were a "real" object.) >> > > Yes again! Got headache thinking of userland devs get this power > without a way to bypass it.
---------- 3/3 ---------- Am 11.02.2014 21:54, schrieb Stas Malyshev:
> Hi! > >> Usecase #2: new maintainer >> Hunting bug in proxy object. No way to dump internals at all. Wait what? > That's exactly what would routinely happen with this proposal. People > would use __debugInfo to pretty-print their object structure, and then > discover they actually have no way to know what's *really* there when > their pretty-printer does not work or does not supply needed > information. So they would eventually ask for real_var_dump().
Thank you again!

Rowan Collins

12 years ago
Crypto Compress wrote (on 11/02/2014):
>> You can still see "the truth" via reflection and by using a proper >> debugger (like xdebug, I assume) >> > > Reflection is mentioned in RFC. Sadly it does not solve the problem. > Replaced output is *not* bypassable without external tools > (xdebug/phpdbg). If i'am wrong correct me. >
The presence of Reflection methods for telling the truth means that a tool can be built entirely in userland (as long as Reflection ext is enabled), which is a lot less "external" than something like xdebug/phpdbg. Regards,
-- Rowan Collins [IMSoP]

Nicolas Grekas

12 years ago
Hi Sara, https://wiki.php.net/rfc/debug-info
>
I can't resist telling you about patchwork/dumper<https://github.com/nicolas-grekas/Patchwork-Dumper>because it has all you seem to look for. Except internal info that are hidden from user land, it has a higher accuracy than var_dump(), because it can dump soft *and* hard references inside complex data structures. It also offers tailor made output with the ability to enrich objects/resources with custom "casters"<https://github.com/nicolas-grekas/Patchwork-Dumper/tree/master/class/Patchwork/Dumper/Caster> . Maybe this can fuel some ideas? For example, I would suggest that any error thrown from a call to __debugInfo() should be ignored by var_dump()/print_r(). Cheers, Nicolas