From 520bb1dc4fad1af39892422923bf4cd3b604ed77 Mon Sep 17 00:00:00 2001 From: Gordon Forsythe Date: Mon, 21 Dec 2020 14:00:10 -0700 Subject: [PATCH] Fix PHP 8 deprecation (#189) --- lib/StandardReflector.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/StandardReflector.php b/lib/StandardReflector.php index 3c63869..6d532c5 100644 --- a/lib/StandardReflector.php +++ b/lib/StandardReflector.php @@ -25,9 +25,17 @@ public function getCtorParams($class) public function getParamTypeHint(\ReflectionFunctionAbstract $function, \ReflectionParameter $param) { - return ($reflectionClass = $param->getClass()) - ? $reflectionClass->getName() - : null; + // php 8 deprecates getClass method + if (PHP_VERSION_ID >= 80000) { + $reflectionClass = $param->getType() ? (string) $param->getType() : null; + } else { + /** @var ?\ReflectionClass $reflectionClass */ + $reflectionClass = $param->getClass(); + if ($reflectionClass) { + $reflectionClass = $reflectionClass->getName(); + } + } + return $reflectionClass ?? null; } public function getFunction($functionName)