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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
34 - 4 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 03:01:32 2024 UTC