php.net |  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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gmblar+php at gmail dot com
New email:
PHP Version: OS:

 

 [2019-11-30 20:09 UTC] gmblar+php at gmail dot com
Description:
------------
Return value of gettype not match the names used as type hints of parameters, properties or ReflectionType.

Test script:
---------------
var_dump(gettype(true));
var_dump(gettype(false));
var_dump(gettype(1337));
var_dump(gettype(23.42));

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"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-30 20:15 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-11-30 20:15 UTC] requinix@php.net
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: Sat Apr 20 00:01:27 2024 UTC