|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79961 Reflection Type method "GetName" returns different values then old gettype()
Submitted: 2020-08-12 10:01 UTC Modified: 2020-08-12 10:07 UTC
From: petr dot vejchoda at seznam dot cz Assigned:
Status: Wont fix Package: Reflection related
PHP Version: 7.4.9 OS: Win10
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.
Block user comment
Status: Assign to:
Bug Type:
From: petr dot vejchoda at seznam dot cz
New email:
PHP Version: OS:


 [2020-08-12 10:01 UTC] petr dot vejchoda at seznam dot cz
From manual page:
Legacy php method gettype() returns different type names for variables then Reflection class methods making it unnecessarily complex to check whether method parameter is the same type of reflected typed property.  

Test script:
class testClass
    public int $int;
    public float $float;
    public bool $bool;
    public string $string;

    public final function __construct()

        $intType = (new \ReflectionClass($this))->getProperty("int");
        $floatType = (new \ReflectionClass($this))->getProperty("float");
        $boolType = (new \ReflectionClass($this))->getProperty("bool");
        $stringType = (new \ReflectionClass($this))->getProperty("string");

        $int = 0;
        $float = 0.0;
        $bool = true;
        $string = 'string';




Expected result:
Expect all booleans to be named the same, all integers, all floating numbers to be  named the same. So that I can check it by string comparison even though I hate to check types by string comparison ...

Actual result:
Mess. Total unholy mess.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-08-12 10:05 UTC]
-Status: Open +Status: Wont fix
 [2020-08-12 10:05 UTC]
The legacy gettype() function will not be changed for backwards-compatibility reasons. PHP 8 introduces get_debug_type() that uses canonical type names, and also returns class names.

However, your premise of checking whether a value satisfies a type declaration using gettype() is unworkable in the first place once non-trivial types get involved (esp. union types).
 [2020-08-12 10:07 UTC]
See also for details on the referenced function.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jun 21 17:01:23 2021 UTC