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
 [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

Pull Requests

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 Dec 13 22:01:27 2024 UTC