From dae57592229d313b59414a2c8334e61e6eb00928 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Thu, 4 Mar 2021 21:26:52 +0100 Subject: [PATCH] Fix error for non-class types on PHP 8 --- lib/StandardReflector.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/StandardReflector.php b/lib/StandardReflector.php index 6d532c5..17ae1ef 100644 --- a/lib/StandardReflector.php +++ b/lib/StandardReflector.php @@ -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)