Bug #78893 [Com]: Inconsistent return value of gettype

From: Date: Mon, 02 Dec 2019 17:15:22 +0000
Subject: Bug #78893 [Com]: Inconsistent return value of gettype
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224015@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78893&edit=1

 ID:                 78893
 Comment by:         krzysiek at example dot com
 Reported by:        gmblar+php at gmail dot com
 Summary:            Inconsistent return value of gettype
 Status:             Not a bug
 Type:               Bug
 Package:            Variables related
 Operating System:   MacOS 10.15.1
 PHP Version:        7.4.0
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2019-12-01 23:32:02] 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-11-30 20:15:08] 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-11-30 20:09:18] 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"


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=78893&edit=1


Thread (4 messages)

« previous php.bugs (#224015) next »