Something new to argue about:
Hi Sara,
Something new to argue about:
Love it, two things: the var_dump()
properties will be replaced (not merged) with the "real" properties in the object (I am asking as that would make it very very cool for stuff like doctrine, where lazy loaded entities are way too large to dump)? As for the name, I would prefer __debugInfo() as in __callStatic(). I know there is __set_state() but that's something that needs deprecation and fixing :)
cu,
Lars
Love it, two things: the
var_dump()
properties will be replaced (not merged) with the "real" properties in the object (I am asking as that would make it very very cool for stuff like doctrine, where lazy loaded entities are way too large to dump)? As for the name, I would prefer __debugInfo() as in __callStatic(). I know there is __set_state() but that's something that needs deprecation and fixing :)
Replaced. The idea being that if you want to merge with the base
props, you can return (array)$this + ['other'=>'props']; or similar.
EXCELLENT point on the method naming, I'll put that version 1.1 of the RFC.
-Sara
hi,
Hi Sara,
Something new to argue about:
Love it, two things: the
var_dump()
properties will be replaced (not merged) with the "real" properties in the object (I am asking as that would make it very very cool for stuff like doctrine, where lazy loaded entities are way too large to dump)? As for the name, I would prefer __debugInfo() as in __callStatic(). I know there is __set_state() but that's something that needs deprecation and fixing :)
I can only second both statements. Love the idea (very useful!) and it
should indeed follow other "magic" method naming convention.
One additional comment, I am not sure about the manual merge of
properties. Maybe it should create an additional property called
"debugInfo" or something similar and store the result of __debugInfo
in it? It could be more user-friendly and less confusing.
Cheers,
Pierre
@pierrejoye | http://www.libgd.org
One additional comment, I am not sure about the manual merge of
properties. Maybe it should create an additional property called
"debugInfo" or something similar and store the result of __debugInfo
in it? It could be more user-friendly and less confusing.
Functionally speaking, the merge has to happen regardless since we
can't just put temporary elements into the properties table and return
that. Sure we could do the work for the user by putting the merge in
the standard object handler, but what does it buy us?
From my point of view, it buys us less options for the user. By
returning the result of __debugInfo() as-is, the class author can
replace, merge, or stuff debug into an extra prop at their discretion.
By making a unilateral decision to merge, we exclude the option of
not including certain props. By making the decision to put
__debugInfo() result into a specific '__debug' prop, we take all the
options away.
Personally, I'm for giving power to the user here. (Not least because
my use-case would quite like being able to control what's shown for
var_dump()
)
-Sara
Updated my branch to use __debugInfo() and updated the RFC to reflect
this and include comments from the list about different ways to handle
the return (replace, merge, sub-element) as well as expanding the
scope to include a ReflectionClass::getDebugInfo() method.
Hi all,
Sorry for off topic.
Love it, two things: the
var_dump()
properties will be replaced (not
merged) with the "real" properties in the object (I am asking as that would
make it very very cool for stuff like doctrine, where lazy loaded entities
are way too large to dump)? As for the name, I would prefer __debugInfo()
as in __callStatic(). I know there is __set_state() but that's something
that needs deprecation and fixing :)
Could anyone add __setState() for 5.6?
Thank you.
BTW, I like the RFC.
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi all,
Sorry for off topic.
Love it, two things: the
var_dump()
properties will be replaced (not
merged) with the "real" properties in the object (I am asking as that would
make it very very cool for stuff like doctrine, where lazy loaded entities
are way too large to dump)? As for the name, I would prefer __debugInfo()
as in __callStatic(). I know there is __set_state() but that's something
that needs deprecation and fixing :)Could anyone add __setState() for 5.6?
Why would you want to do that? If at all, all the newer methods should
be __debug_info etc. __set_state was first and changing it to
__setState() would mean that var_export'ed() variables in < PHP 5.6
would now no longer work? Or the other way around? It's a cosmetic
change that helps nobody—just like renaming other standard functions to
make them more "organised".
cheers,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine
Hi Derick,
Hi all,
Sorry for off topic.
Love it, two things: the
var_dump()
properties will be replaced (not
merged) with the "real" properties in the object (I am asking as that
would
make it very very cool for stuff like doctrine, where lazy loaded
entities
are way too large to dump)? As for the name, I would prefer
__debugInfo()
as in __callStatic(). I know there is __set_state() but that's
something
that needs deprecation and fixing :)Could anyone add __setState() for 5.6?
Why would you want to do that? If at all, all the newer methods should
be __debug_info etc. __set_state was first and changing it to
__setState() would mean that var_export'ed() variables in < PHP 5.6
would now no longer work? Or the other way around? It's a cosmetic
change that helps nobody—just like renaming other standard functions to
make them more "organised".cheers,
I mean add alias for __set_state() to keep consistent names.
__set_state() should be there very long time or forever for compatibility.
It's small cosmetic change, but it would assure PHP to be a good
language to learn in the future. IMHO.
Anyway, I would like to write RFC for aliasing. Aliases may be added
in the future.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Love it, two things: the
var_dump()
properties will be replaced
(not merged) with the "real" properties in the object (I am
asking as that would make it very very cool for stuff like
doctrine, where lazy loaded entities are way too large to dump)?
As for the name, I would prefer __debugInfo() as in
__callStatic(). I know there is __set_state() but that's
something that needs deprecation and fixing :)Could anyone add __setState() for 5.6?
Why would you want to do that? If at all, all the newer methods
should be __debug_info etc. __set_state was first and changing it to
__setState() would mean that var_export'ed() variables in < PHP 5.6
would now no longer work? Or the other way around? It's a cosmetic
change that helps nobody—just like renaming other standard functions
to make them more "organised".I mean add alias for __set_state() to keep consistent names.
__set_state() should be there very long time or forever for
compatibility.
You seem to misunderstand what __set_state() is for. It is for reliably
representing a value so that you can "include" it's contents with
var_export()
. If 5.6 would suddenly start spitting out
Class::__setState() instead of Classs::__set_state() then older PHP
versions can't parse/include that outputted data anymore.
It's small cosmetic change, but it would assure PHP to be a good
language to learn in the future. IMHO.
But it makes as much sense as adding a str_len() function as alias for
strlen()
— which really just adds more clutter.
Anyway, I would like to write RFC for aliasing. Aliases may be added
in the future.Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine
Hi Derick,
Could anyone add __setState() for 5.6?
Why would you want to do that? If at all, all the newer methods
should be __debug_info etc. __set_state was first and changing it to
__setState() would mean that var_export'ed() variables in < PHP 5.6
would now no longer work? Or the other way around? It's a cosmetic
change that helps nobody—just like renaming other standard functions
to make them more "organised".I mean add alias for __set_state() to keep consistent names.
__set_state() should be there very long time or forever for
compatibility.You seem to misunderstand what __set_state() is for. It is for reliably
representing a value so that you can "include" it's contents with
var_export()
. If 5.6 would suddenly start spitting out
Class::__setState() instead of Classs::__set_state() then older PHP
versions can't parse/include that outputted data anymore.
I have to check code, but don't we have options for this?
We may use __set_state() for var_export and still have alias as __setState.
People are using var_export exchange PHP data, so we should be careful.
I agree this.
It's small cosmetic change, but it would assure PHP to be a good
language to learn in the future. IMHO.
But it makes as much sense as adding a str_len
I understand both opinion, strlen could be str_len. Other str function may
be reamed.
Some names are easy to decide, some are not. We may have list of votes
for these. I'll make list after 5.6 release :)
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Yasuo Ohgaki wrote (on 23/01/2014):
You seem to misunderstand what __set_state() is for. It is for reliably
representing a value so that you can "include" it's contents with
var_export(). If 5.6 would suddenly start spitting out
Class::__setState() instead of Classs::__set_state() then older PHP
versions can't parse/include that outputted data anymore.I have to check code, but don't we have options for this?
We may use __set_state() for var_export and still have alias as __setState.
People are using var_export exchange PHP data, so we should be careful.
I agree this.
Is there a use case for __set_state other than var_export()
?
In other words, if not var_export()
, what code would ever include a
reference to __setState() if it were added as an alias?
--
Rowan Collins
[IMSoP]
Hi Rowan,
On Thu, Feb 6, 2014 at 4:36 AM, Rowan Collins rowan.collins@gmail.comwrote:
You seem to misunderstand what __set_state() is for. It is for reliably
representing a value so that you can "include" it's contents with
var_export(). If 5.6 would suddenly start spitting out
Class::__setState() instead of Classs::__set_state() then older PHP
versions can't parse/include that outputted data anymore.I have to check code, but don't we have options for this?
We may use __set_state() for var_export and still have alias as
__setState.
People are using var_export exchange PHP data, so we should be careful.
I agree this.Is there a use case for __set_state other than
var_export()
?In other words, if not
var_export()
, what code would ever include a
reference to __setState() if it were added as an alias?
My bad.
var_export()
does not specify method, so it can alias safely.
Regards,
--
Yasuo Ohgaki
yohgaki@ohgaki.net
Hi Sara,
Something new to argue about:
This is a really good idea. This will allow customization of the debug
info, and reflection to Reflection. That said, how/should this
functionality be integrated info Reflection? For example,
ReflectionClass::getDebugInfo()?
Something new to argue about:
This is a really good idea. This will allow customization of the debug
info, and reflection to Reflection. That said, how/should this
functionality be integrated info Reflection? For example,
ReflectionClass::getDebugInfo()?
I think it'd make sense to add that as well, yes. Regardless of
whether or not this RFC gets accepted, in fact.
As to how, I'd treat that method just like getProperties() (Creating
an array of ReflectionProperty objects), just from a different source.
-Sara
Hi all !
Le 21 janv. 2014 à 22:26, Sara Golemon pollita@php.net a écrit :
Something new to argue about:
Very interesting feature (i have personally thinking about that several time in the past).
However, i think that __dump() is a better name from the end user point of view.
__debug_info() is a good name from the point of view of a C developer which works on the Zend Engine or on C extensions, but from the end user point of view, it’s not the case.
And this new magical method is used internally by var_dump()
so __dump() seems to me a better name.
Maybe __set_dump() is an alternative too, because __set_state() is used internally by var_export()
, but i’m not sure that it’s a better name than __dump which is very explicit and intuitive.
Best regards,
Fred.
========================================================================
Frédéric Hardy : Directeur technique et fonctionnel agile
CV : http://blog.mageekbox.net/public/cv.frederic.hardy.pdf
Blog : http://blog.mageekbox.net
Twitter : http://twitter.com/mageekguy
Hello :-),
Hi all !
Le 21 janv. 2014 à 22:26, Sara Golemon pollita@php.net a écrit :
Something new to argue about:
https://wiki.php.net/rfc/debug-info
Very interesting feature (i have personally thinking about that several time in the past).
However, i think that __dump() is a better name from the end user point of view.
__debug_info() is a good name from the point of view of a C developer which works on the Zend Engine or on C extensions, but from the end user point of view, it’s not the case.
And this new magical method is used internally byvar_dump()
so __dump() seems to me a better name.
Maybe __set_dump() is an alternative too, because __set_state() is used internally byvar_export()
, but i’m not sure that it’s a better name than __dump which is very explicit and intuitive.
+1 for__debug
which is simpler than__debugInfo
. The -info suffix
does not add any relevant meaning about the method behavior.
Moreover, is this method able to throw an exception?
Cheers.
--
Ivan Enderlin
Developer of Hoa
http://hoa-project.net/
PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis)
http://disc.univ-fcomte.fr/ and http://www.inria.fr/
Member of HTML and WebApps Working Group of W3C
http://w3.org/
Hello!
I would like to notice, that there is method __set_state() that can be used
to set internal state of object. We can introduce __get_state() method that
will be invoked in var_dump()
, etc... Personally I don't like __lower_caps
name of this method, but it will be consistent with __set_state() :)
2014/1/22 Ivan Enderlin @ Hoa ivan.enderlin@hoa-project.net
Hello :-),
Hi all !
Le 21 janv. 2014 à 22:26, Sara Golemon pollita@php.net a écrit :
Something new to argue about:
Very interesting feature (i have personally thinking about that several
time in the past).
However, i think that __dump() is a better name from the end user point
of view.
__debug_info() is a good name from the point of view of a C developer
which works on the Zend Engine or on C extensions, but from the end user
point of view, it’s not the case.
And this new magical method is used internally byvar_dump()
so __dump()
seems to me a better name.
Maybe __set_dump() is an alternative too, because __set_state() is used
internally byvar_export()
, but i’m not sure that it’s a better name than
__dump which is very explicit and intuitive.+1 for
__debug
which is simpler than__debugInfo
. The -info suffix
does not add any relevant meaning about the method behavior.Moreover, is this method able to throw an exception?
Cheers.
--
Ivan Enderlin
Developer of Hoa
http://hoa-project.net/PhD. student at DISC/Femto-ST (Vesontio) and INRIA (Cassis)
http://disc.univ-fcomte.fr/ and http://www.inria.fr/Member of HTML and WebApps Working Group of W3C
http://w3.org/
Hello!
I would like to notice, that there is method __set_state() that can be used
to set internal state of object. We can introduce __get_state() method that
will be invoked invar_dump()
, etc... Personally I don't like __lower_caps
name of this method, but it will be consistent with __set_state() :)
__set_state() is only meant for userland, not for internals.
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine
Hi Derick,
__set_state() is only meant for userland, not for internals.
Sure, it still is still inconsistent with the remaining methods.
cu,
Lars
__set_state() is only meant for userland, not for internals.
Sure, it still is still inconsistent with the remaining methods.
You seem to have the order of events the wrong way around. __callStatic,
and __toString were added after __set_state() so these additions made
things "inconsistent".
cheers,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Posted with an email client that doesn't mangle email: alpine
+1 for
__debug
which is simpler than__debugInfo
. The -info suffix
does not add any relevant meaning about the method behavior.
I feel the same here. PHP already has plenty of names which are longer
than they ought to be, or redundant, let's not add another. :)
--
Andrea Faulds
http://ajf.me/
Hi
Something new to argue about:
What impact does this have to debuggers like Xdebug?
A comment: PHP in most places like var_dump()
usually shows the truth, I
think that is nice ... reason why internal classes have this hook is
that there is no truth.
I assume a cast to array and ReflectionObject will still show the truth?
This should be mentioned in the RFC so it can be added to var_dump()
docs in case this is accepted.
johannes
On Tue, Jan 21, 2014 at 1:56 PM, Johannes Schlüter
johannes@schlueters.de wrote:
What impact does this have to debuggers like Xdebug?
I'd want Derick to weigh in on that. I'm not sure if XDebug only
looks at the get_properties hook, or considers the get_debug_info hook
as well.
A comment: PHP in most places like
var_dump()
usually shows the truth, I
think that is nice ... reason why internal classes have this hook is
that there is no truth.
I'm not sure I agree with the latter part of that statement. If the
hook existed to allow internal classes to "expose truth", they could
do so via get_properties.
I assume a cast to array and ReflectionObject will still show the truth?
Yes. Cast to array and ReflectionObject::getProperties() both look at
the get_properties handler which is not impacted.
-Sara
On Tue, Jan 21, 2014 at 1:56 PM, Johannes Schlüter
johannes@schlueters.de wrote:What impact does this have to debuggers like Xdebug?
I'd want Derick to weigh in on that. I'm not sure if XDebug only
looks at the get_properties hook, or considers the get_debug_info hook
as well.
Not yet, but I was hacking on a branch that uses that hook too, as it's
pretty handy to expose through the debugger. I'd probably namespace it
though so it doesn't conflict with "real" properties.
cheers,
Derick
Hi,
why not use __toString?
class File {
// "Resource(stream)" isn't all that useful
private $fp;
// But all the stream meta data is
public function __toString() {
return $this->fp ? print_r(stream_get_meta_data($this->fp),
true) : ''; // var export, what ever you like
}
public function open($filename, $mode = 'r'){
$this->fp = fopen($filename, $mode);
}
}
$f = new File;
echo $f; // object(File)#1 { }
$f->open('http://php.net');
echo $f;
cryptocompress
Hi,
why not use __toString?
class File {
// "Resource(stream)" isn't all that useful
private $fp;// But all the stream meta data is public function __toString() { return $this->fp ? print_r(stream_get_meta_data($this->fp),
true) : ''; // var export, what ever you like
}public function open($filename, $mode = 'r'){ $this->fp = fopen($filename, $mode); }
}
$f = new File;
echo $f; // object(File)#1 { }
$f->open('http://php.net');
echo $f;cryptocompress
Because the __toString allows a class to decide how to react when
treated like a string. Sure, that could be debug info, but it could be
printing a full-blow decorator implementation (e.g. Zend\Form\Form), a
number, class name, etc. What Sara is proposing is specific to object
debugging.
Because the __toString allows a class to decide how to react when
treated like a string. Sure, that could be debug info, but it could be
printing a full-blow decorator implementation (e.g. Zend\Form\Form), a
number, class name, etc. What Sara is proposing is specific to object
debugging.
Right. To see the difference better, I suggest looking at what Python
does. It has a string() magic method and a repr() magic method,
for string conversion and debug info, respectively. For a date, these
result in:
x = datetime.datetime(1996, 02, 17)
x
datetime.datetime(1996, 2, 17, 0, 0)
str(x)
'1996-02-17 00:00:00'
repr(x)
'datetime.datetime(1996, 2, 17, 0, 0)'
While the str() result is what you want for displaying that date, the
repr() result shows you how it was constructed, which is more useful for
debugging.
For another example, see what Python strings do here:
n = "line 1\nline 2"
print n
line 1
line 2
print repr(n)
'line 1\nline 2'
The first one's might not be very useful for debugging, because it
outputs control characters raw. The debug output version, however, is
much better for this.
--
Andrea Faulds
http://ajf.me/
Something new to argue about:
Good proposal. Python has repr, and it's a useful feature for
debugging. I see no reason why PHP shouldn't have its own equivalent.
--
Andrea Faulds
http://ajf.me/