php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79290 getType doesn't return a type
Submitted: 2020-02-20 11:34 UTC Modified: 2020-02-20 12:53 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: dalius dot ulevicius at gmail dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 7.4.2 OS:
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: dalius dot ulevicius at gmail dot com
New email:
PHP Version: OS:

 

 [2020-02-20 11:34 UTC] dalius dot ulevicius at gmail dot com
Description:
------------
Reflection getType function doesn't return a type

Test script:
---------------
function someFunction(string $param, int $param2 = null) {}

$reflectionFunc = new ReflectionFunction('someFunction');
$reflectionParams = $reflectionFunc->getParameters();

var_dump($reflectionParams[0]->hasType());
echo '<br>';
var_dump($reflectionParams[1]->hasType());
echo '<br>';
var_dump($reflectionParams[0]->getType());
echo '<br>';
var_dump($reflectionParams[1]->getType());

Expected result:
----------------
bool(true)
bool(true)
string
int

Actual result:
--------------
bool(true)
bool(true)
class ReflectionNamedType#4 (0) { }
class ReflectionNamedType#4 (0) { }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-02-20 12:53 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2020-02-20 12:53 UTC] nikic@php.net
See https://www.php.net/reflectionnamedtype for information on the object that is being returned. You can get the name of the type using $type->getName().

You really could have figured this out yourself.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 22:01:28 2024 UTC