Skip to content

Commit

Permalink
Fix error for non-class types on PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Mar 4, 2021
1 parent 306e7a8 commit dae5759
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/StandardReflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ public function getParamTypeHint(\ReflectionFunctionAbstract $function, \Reflect
{
// php 8 deprecates getClass method
if (PHP_VERSION_ID >= 80000) {
$reflectionClass = $param->getType() ? (string) $param->getType() : null;
$type = $param->getType();
if ($type instanceof \ReflectionNamedType && $type->isBuiltin()) {
return null;
}

return $type ? (string) $type : null;
} else {
/** @var ?\ReflectionClass $reflectionClass */
$reflectionClass = $param->getClass();
if ($reflectionClass) {
$reflectionClass = $reflectionClass->getName();
return $reflectionClass->getName();
}

return null;
}
return $reflectionClass ?? null;
}

public function getFunction($functionName)
Expand Down

0 comments on commit dae5759

Please sign in to comment.