Skip to content

Commit 14af03b

Browse files
author
Diederik Noordhuis
authored
Fix PHP 7.0 break due to undefined method.
1 parent 9c9a578 commit 14af03b

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

lib/Phpfastcache/Config/ConfigurationOption.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,24 @@ public function __construct(...$args)
142142
$typeHintGot = \is_object($value) ? \get_class($value) : \gettype($value);
143143
$reflectionMethod = new \ReflectionMethod($this, $method);
144144
$parameter = $reflectionMethod->getParameters()[0] ?? null;
145-
$typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($parameter->getType()->getName() === 'object' ? $parameter->getClass() : $parameter->getType()->getName()) : 'Unknown type');
146-
147-
throw new PhpfastcacheInvalidConfigurationException(\sprintf(
148-
'Invalid type hint found for "%s", expected "%s" got "%s"',
149-
\lcfirst(\substr($method, 3)),
150-
$typeHintExpected,
151-
$typeHintGot
152-
));
145+
$paraReflectionType = $parameter->getType();
146+
if(method_exists($paraReflectionType, "getName")) {
147+
$typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($paraReflectionType->getName() === 'object' ? $parameter->getClass() : $paraReflectionType->getName()) : 'Unknown type');
148+
throw new PhpfastcacheInvalidConfigurationException(\sprintf(
149+
'Invalid type hint found for "%s", expected "%s" got "%s"',
150+
\lcfirst(\substr($method, 3)),
151+
$typeHintExpected,
152+
$typeHintGot
153+
));
154+
} else {
155+
$typeHintExpected = ($parameter instanceof \ReflectionParameter ? ($paraReflectionType === 'object' ? $parameter->getClass() : $paraReflectionType) : 'Unknown type');
156+
throw new PhpfastcacheInvalidConfigurationException(\sprintf(
157+
'Invalid type hint found for "%s", expected "%s" got "%s"',
158+
\lcfirst(\substr($method, 3)),
159+
$typeHintExpected,
160+
$typeHintGot
161+
));
162+
}
153163
}
154164
}
155165
}

0 commit comments

Comments
 (0)