php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74742 ReflectionParameter::getType returns "int", gettype returns "integer"
Submitted: 2017-06-11 07:24 UTC Modified: 2017-06-11 08:02 UTC
From: pierre at lgse dot com Assigned:
Status: Wont fix Package: Variables related
PHP Version: 7.0Git-2017-06-11 (Git) OS: CentOS
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: pierre at lgse dot com
New email:
PHP Version: OS:

 

 [2017-06-11 07:24 UTC] pierre at lgse dot com
Description:
------------
ReflectionParameter::getType should return "integer" and not "int" on a constructor parameter of type "int". 

The types returned by ReflectionParameter::getType and the gettype() function should be the same.



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-06-11 07:37 UTC] spam2 at rhsoft dot net
Provide a code sample - I have written a fuzzy testsuite based on reflection and didn't face such issurs6
 [2017-06-11 07:52 UTC] joey@php.net
<?php
class A {
    public function __construct(int $a){
        $this->a = $a;
    }
}

var_dump((string)(new ReflectionClass('A'))->getConstructor()->getParameters()[0]->getType(), gettype(0));
 [2017-06-11 07:53 UTC] joey@php.net
Above code returns:

string(3) "int"
string(7) "integer"
 [2017-06-11 08:02 UTC] requinix@php.net
-Summary: ReflectionParameter::getType +Summary: ReflectionParameter::getType returns "int", gettype returns "integer" -Status: Open +Status: Wont fix -Package: Reflection related +Package: Variables related
 [2017-06-11 08:02 UTC] requinix@php.net
PHP has decided to go with "int", as seen in
  https://wiki.php.net/rfc/scalar_type_hints_v5
  https://wiki.php.net/rfc/reserve_more_types_in_php_7
so gettype() is the one that doesn't match, however it cannot be changed due to backwards compatibility.
Besides, the is_* functions are generally recommended over gettype() anyways.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 25 20:03:37 2021 UTC