# Change output of gettype?

- Thread: https://externals.io/message/129485
- Original archive: https://news-web.php.net/php.internals/129485
- Started by BohwaZ on 2025-12-01T20:12:36+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #129485 — BohwaZ — 2025-12-01T20:12:36+00:00

URL: https://externals.io/message/129485#129485

Hi all,

PHP 8.5 has deprecated the following type names:
- integer
- double
- boolean
- binary

But the `gettype()` function still returns integer, double and boolean
instead of int, float and bool.

This inconsistency is quite confusing for new developers (and even older
ones).

I understand that changing the return of gettype might break a lot of
existing code, so maybe it's not a good idea (yet).

But maybe we could add a parameter to gettype, for example:

gettype(mixed $value, bool $strict = false): string

If true, then it would return the "new" canonical names. And then in
the next version emit a depreciation notice if $strict is not supplied.

And then in PHP 9 maybe change the default return of gettype, but still
allow to pass $strict = false, so that upgrading the existing code base
would just be a matter of doing a regexp replace of gettype(...) to
gettype(..., false).

Adding a depreciation notice if $strict is not supplied would make
things just painful for everyone I think though.

It's a small thing but it seems like having the same canonical names
everywhere would make things more consistent.

Or the cheap solution would be to just add the $strict parameter
and update the gettype documentation to say that the types returned
by default are not the "new" scalar and passing $strict is needed in
order to match what "new" PHP is using.

Cheers everyone.

---

## #129487 — Thomas Bley — 2025-12-01T20:52:11+00:00

URL: https://externals.io/message/129485#129487 · In reply to: #129485

> BohwaZ <php@bohwaz.net> hat am 01.12.2025 21:12 CET geschrieben:
> 
>  
> Hi all,
> 
> PHP 8.5 has deprecated the following type names:
> - integer
> - double
> - boolean
> - binary
> 
> But the `gettype()` function still returns integer, double and boolean
> instead of int, float and bool.
> 
> This inconsistency is quite confusing for new developers (and even older
> ones).
> 
> I understand that changing the return of gettype might break a lot of
> existing code, so maybe it's not a good idea (yet).
> 
> But maybe we could add a parameter to gettype, for example:
> 
> gettype(mixed $value, bool $strict = false): string
> 
> If true, then it would return the "new" canonical names. And then in
> the next version emit a depreciation notice if $strict is not supplied.
> 
> And then in PHP 9 maybe change the default return of gettype, but still
> allow to pass $strict = false, so that upgrading the existing code base
> would just be a matter of doing a regexp replace of gettype(...) to
> gettype(..., false).
> 
> Adding a depreciation notice if $strict is not supplied would make
> things just painful for everyone I think though.
> 
> It's a small thing but it seems like having the same canonical names
> everywhere would make things more consistent.
> 
> Or the cheap solution would be to just add the $strict parameter
> and update the gettype documentation to say that the types returned
> by default are not the "new" scalar and passing $strict is needed in
> order to match what "new" PHP is using.
> 
> Cheers everyone.

Hello,

thank you! To me it makes sense and improves consistency.
Instead of returning a String it would be also possible to return an Enum but that would more likely be a new function.

There were previous rfcs for new functions:
https://wiki.php.net/rfc/var_type
https://wiki.php.net/rfc/var_info

Best Regards
Thomas

---

## #129488 — Pierre — 2025-12-01T20:55:31+00:00

URL: https://externals.io/message/129485#129488 · In reply to: #129485

Le 01/12/2025 à 21:12, BohwaZ a écrit :
> Hi all,
>
> PHP 8.5 has deprecated the following type names:
> - integer
> - double
> - boolean
> - binary
>
> But the `gettype()` function still returns integer, double and boolean
> instead of int, float and bool.
>
> This inconsistency is quite confusing for new developers (and even older
> ones).
>
> I understand that changing the return of gettype might break a lot of
> existing code, so maybe it's not a good idea (yet).

And if I remember correctly, that's exactly why `get_debug_type()` was 
introduced: no BC break, and it does the job.

You should simply use `get_debug_type()` everywhere and never use 
 `gettype()` ever again. This is the most sensible move you can make, it 
really is the function you should use in most case.

--

Pierre

---

## #129509 — BohwaZ — 2025-12-02T13:45:42+00:00

URL: https://externals.io/message/129485#129509 · In reply to: #129488

> And if I remember correctly, that's exactly why `get_debug_type()` was 
> introduced: no BC break, and it does the job.
> 
> You should simply use `get_debug_type()` everywhere and never use 
> `gettype()` ever again. This is the most sensible move you can make, it 
> really is the function you should use in most case.

Ah! I've never heard of this function before in my last 25 years of
PHP ^^

I'll open a PR to change the doc about gettype to make it clearer in
the gettype page that get_debug_type should be used in priority.

Thanks.
