|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78893 Inconsistent return value of gettype
Submitted: 2019-11-30 20:09 UTC Modified: 2019-11-30 20:15 UTC
From: gmblar+php at gmail dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 7.4.0 OS: MacOS 10.15.1
Private report: No CVE-ID: None
 [2019-11-30 20:09 UTC] gmblar+php at gmail dot com
Return value of gettype not match the names used as type hints of parameters, properties or ReflectionType.

Test script:

Expected result:
string(4) "bool"
string(4) "bool"
string(3) "int"
string(5) "float"

Actual result:
string(7) "boolean"
string(7) "boolean"
string(7) "integer"
string(6) "double"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-30 20:15 UTC]
-Status: Open +Status: Not a bug
 [2019-11-30 20:15 UTC]
The returned strings are perfectly adequate and have existed as such since forever. Changing it just because scalar types use different names isn't a good enough reason to break BC.
 [2019-12-01 23:32 UTC] sdsdsdsdsd at sdfdfdfdfdfdf dot net
yeah, to late now, smart development would have leaded in calling the scalar types 'boolean', 'integer', and 'double' for the sake of consistency, but hesy it's PHP
 [2019-12-02 17:15 UTC] krzysiek at example dot com
You can find 18 million results for "gettype" in php on github. It would be irresponsible to mess with that old function. There is no problem to just write your own implementation using a few is_* or switch. These days there is rather uncommon to have variable which have more than 2 types possible, so is_* are more than enough. And gettype is now mainly useful in unit testing.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 12 22:01:29 2024 UTC