> Le 10 juil. 2025 à 13:18, Gina P. Banyard <intern...@gpb.moe> a écrit : > > On Wednesday, 9 July 2025 at 22:26, Claude Pache <claude.pa...@gmail.com> > wrote: >> Hi, >> >> A possible reason for wanting to use the non-canonical names in settype(), >> is that those names are returned by gettype(). Fictional example (not >> intended to be reasonable, only illustrative): >> >> ```php >> function settype_from(&$a, &b) { >> return settype($a, gettype($b)); >> } >> ``` >> >> Personally, I have used "integer", etc. instead of "int", etc., in >> settype() in the past, because those were the “canonical” (as I perceived) >> forms returned by gettype(). I have slowly fallen out of that habit in the >> years after I began to use scalar type declarations (introduced in PHP 7). > > We are well aware of this "issue" and get_debug_type() was introduced in PHP > 8 as a replacement for gettype() that returns the canonical names. > The one difference is that objects return the class name rather than "object". > I can add a deprecation of gettype() to nudge people to use get_debug_type() > instead, if you think that's reasonable. > > Best regards, > > Gina P. Banyard
Hi, Sorry for having forgotten to answer to this point. To be clearer, I think it is fine for `settype()` to keep support for the legacy names ("integer", "boolean", etc.) returned by `gettype()`, even if we deprecate the syntax `(integer) $x`, etc. The syntax `(integer)` is trivial to correct with a simple search-and-replace; such a correction is not straightforward for `settype($a, $type)` as $type is not necessarily a literal string. Moreover, the $type argument in `settype()` is not confusable with hypothetical user-defined types named, e.g., `integer`, as user-defined types are forbidden in `settype()` anyway. —Claude