[RFC] get_debug_type

  108597
February 15, 2020 14:32 markyr@gmail.com (Mark Randall)
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
  108599
February 15, 2020 15:07 nikita.ppv@gmail.com (Nikita Popov)
On Sat, Feb 15, 2020 at 3:33 PM Mark Randall <markyr@gmail.com> wrote:

> 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
  108638
February 17, 2020 08:42 nikita.ppv@gmail.com (Nikita Popov)
On Sat, Feb 15, 2020 at 4:07 PM Nikita Popov ppv@gmail.com> wrote:

> On Sat, Feb 15, 2020 at 3:33 PM Mark Randall <markyr@gmail.com> wrote: > >> 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 >
ping
  108640
February 17, 2020 09:46 marandall@php.net (Mark Randall)
On 17/02/2020 08:42, Nikita Popov wrote:
>> 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
  108616
February 16, 2020 10:16 mike@newclarity.net (Mike Schinkel)
> On Feb 15, 2020, at 9:32 AM, Mark Randall <markyr@gmail.com> wrote: > > 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 >
Why "debug" type? -Mike
  108621
February 16, 2020 13:15 marandall@php.net (Mark Randall)
On 16/02/2020 10:16, Mike Schinkel wrote:
> 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
  108631
February 17, 2020 02:22 tysonandre775@hotmail.com (tyson andre)
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
  108636
February 17, 2020 08:10 tom@inventis.be (Tom Gerrits)
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::type, and so on.
  108794
February 29, 2020 22:41 marandall@php.net (Mark Randall)
On 15/02/2020 14:32, Mark Randall wrote:

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