From 9c9a57894b8b811aa564048864cc530120082518 Mon Sep 17 00:00:00 2001 From: Diederik Noordhuis Date: Sat, 8 Aug 2020 15:23:25 -0500 Subject: [PATCH 1/2] PHP 7.4 support --- lib/Phpfastcache/Config/ConfigurationOption.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Phpfastcache/Config/ConfigurationOption.php b/lib/Phpfastcache/Config/ConfigurationOption.php index 2392f747b..a98a5d41f 100644 --- a/lib/Phpfastcache/Config/ConfigurationOption.php +++ b/lib/Phpfastcache/Config/ConfigurationOption.php @@ -142,7 +142,7 @@ public function __construct(...$args) $typeHintGot = \is_object($value) ? \get_class($value) : \gettype($value); $reflectionMethod = new \ReflectionMethod($this, $method); $parameter = $reflectionMethod->getParameters()[0] ?? null; - $typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($parameter->getType() === 'object' ? $parameter->getClass() : $parameter->getType()) : 'Unknown type'); + $typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($parameter->getType()->getName() === 'object' ? $parameter->getClass() : $parameter->getType()->getName()) : 'Unknown type'); throw new PhpfastcacheInvalidConfigurationException(\sprintf( 'Invalid type hint found for "%s", expected "%s" got "%s"', @@ -447,4 +447,4 @@ public function setCacheSlamsTimeout(int $cacheSlamsTimeout): self $this->cacheSlamsTimeout = $cacheSlamsTimeout; return $this; } -} \ No newline at end of file +} From 14af03b17c8da3f06c8bbf89b54ec80dd95adf3f Mon Sep 17 00:00:00 2001 From: Diederik Noordhuis Date: Sat, 8 Aug 2020 15:39:25 -0500 Subject: [PATCH 2/2] Fix PHP 7.0 break due to undefined method. --- .../Config/ConfigurationOption.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/Phpfastcache/Config/ConfigurationOption.php b/lib/Phpfastcache/Config/ConfigurationOption.php index a98a5d41f..cecfdd5d2 100644 --- a/lib/Phpfastcache/Config/ConfigurationOption.php +++ b/lib/Phpfastcache/Config/ConfigurationOption.php @@ -142,14 +142,24 @@ public function __construct(...$args) $typeHintGot = \is_object($value) ? \get_class($value) : \gettype($value); $reflectionMethod = new \ReflectionMethod($this, $method); $parameter = $reflectionMethod->getParameters()[0] ?? null; - $typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($parameter->getType()->getName() === 'object' ? $parameter->getClass() : $parameter->getType()->getName()) : 'Unknown type'); - - throw new PhpfastcacheInvalidConfigurationException(\sprintf( - 'Invalid type hint found for "%s", expected "%s" got "%s"', - \lcfirst(\substr($method, 3)), - $typeHintExpected, - $typeHintGot - )); + $paraReflectionType = $parameter->getType(); + if(method_exists($paraReflectionType, "getName")) { + $typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($paraReflectionType->getName() === 'object' ? $parameter->getClass() : $paraReflectionType->getName()) : 'Unknown type'); + throw new PhpfastcacheInvalidConfigurationException(\sprintf( + 'Invalid type hint found for "%s", expected "%s" got "%s"', + \lcfirst(\substr($method, 3)), + $typeHintExpected, + $typeHintGot + )); + } else { + $typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($paraReflectionType === 'object' ? $parameter->getClass() : $paraReflectionType) : 'Unknown type'); + throw new PhpfastcacheInvalidConfigurationException(\sprintf( + 'Invalid type hint found for "%s", expected "%s" got "%s"', + \lcfirst(\substr($method, 3)), + $typeHintExpected, + $typeHintGot + )); + } } } }