Greetings,
I offer a short RFC to add a new function, get_debug_type, which would
return the type name of a variable, automatically resolving the class
name in the event of it being an object.
Unlike gettype, this function will return the true name of scalar
types, rather than their aliases, thus get_debug_type will return
"int" rather than "integer" etc.
https://wiki.php.net/rfc/get_debug_type
Mark Randall
marandall@php.net
Greetings,
I offer a short RFC to add a new function, get_debug_type, which would
return the type name of a variable, automatically resolving the class
name in the event of it being an object.Unlike gettype, this function will return the true name of scalar
types, rather than their aliases, thus get_debug_type will return
"int" rather than "integer" etc.https://wiki.php.net/rfc/get_debug_type
Mark Randall
marandall@php.net
Can you please add some examples for the behavior? Preferably the precise
output for all primitive types, for classes and for anonymous classes.
Regards,
Nikita
Greetings,
I offer a short RFC to add a new function, get_debug_type, which would
return the type name of a variable, automatically resolving the class
name in the event of it being an object.Unlike gettype, this function will return the true name of scalar
types, rather than their aliases, thus get_debug_type will return
"int" rather than "integer" etc.https://wiki.php.net/rfc/get_debug_type
Mark Randall
marandall@php.netCan you please add some examples for the behavior? Preferably the precise
output for all primitive types, for classes and for anonymous classes.Regards,
Nikita
ping
Can you please add some examples for the behavior? Preferably the precise
output for all primitive types, for classes and for anonymous classes.
Added to RFC
Greetings,
I offer a short RFC to add a new function, get_debug_type, which would
return the type name of a variable, automatically resolving the class
name in the event of it being an object.Unlike gettype, this function will return the true name of scalar
types, rather than their aliases, thus get_debug_type will return
"int" rather than "integer" etc.
Why "debug" type?
-Mike
Why "debug" type?
I would imagine because it is only really useful in the context of
debugging. There is no reason to ever expose such information to userland.
The name is up for debate.
--
Mark Randall
marandall@php.net
I'd definitely agree on returning int
instead of integer
.
PHP allows both class integer
and class resource
, so int
(plus documenting exact return values for examples, as Nikita mentioned) would be useful to prevent ambiguity.
Also, it'd be nice to have null
return the lowercase string null instead of uppercase.
get_canonical_type() is my weak preference. I'd also considered suggesting get_class_or_type(),
but that seemed misleading since the value of get_class_or_type(2) would be different from gettype(2).
This would save some time and make it easier to write better messages debugging, syslogging, throwing exceptions for unexpected values, etc.
- Tyson
Hi Mark
Thanks for this proposal.
After the proposal by Nikita to allow ::class on object variables,
would it be opportune to add ::type for any variable, with this
behavior?
It could behave like ::class on objects and return a string indicator
of the type for other types, such as scalar ones.
This could even include allowing ::type on actual types, i.e.
int::type, MyClass::type, $myVar::type,
GenericTypeInTheFuture<T>::type, and so on.
Greetings,
https://wiki.php.net/rfc/get_debug_type
Just a heads up that I will be putting this to the vote tomorrow.
As this seems fairly uncontroversial, and in the absence of any
well-supported suggestions, the vote will be on adding this as
get_debug_type.
Unless someone chimes in with a major objection, I do not plan on having
a separate vote on the "resource (type)" style and will include it by
default.
--
Mark Randall
marandall@php.net