From bb967b3dd372fbd93629133758b30c4342442e58 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 14 Jul 2024 12:08:28 +0200 Subject: [PATCH] Make compatible with PHP<8 --- src/Node/Expression/CallExpression.php | 8 ++++++-- src/Util/ReflectionCallable.php | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Node/Expression/CallExpression.php b/src/Node/Expression/CallExpression.php index 19b7d1bad..997e8dc9f 100644 --- a/src/Node/Expression/CallExpression.php +++ b/src/Node/Expression/CallExpression.php @@ -19,7 +19,7 @@ use Twig\Util\ReflectionCallable; abstract class CallExpression extends AbstractExpression { - private ?ReflectionCallable $reflector = null; + private $reflector = null; protected function compileCallable(Compiler $compiler) { @@ -295,6 +295,10 @@ abstract class CallExpression extends AbstractExpression private function reflectCallable($callable): ReflectionCallable { - return $this->reflector ??= new ReflectionCallable($callable, $this->getAttribute('type'), $this->getAttribute('name')); + if (!$this->reflector) { + $this->reflector = new ReflectionCallable($callable, $this->getAttribute('type'), $this->getAttribute('name')); + } + + return $this->reflector; } } diff --git a/src/Util/ReflectionCallable.php b/src/Util/ReflectionCallable.php index 5b593e58d..312a8c7af 100644 --- a/src/Util/ReflectionCallable.php +++ b/src/Util/ReflectionCallable.php @@ -18,9 +18,9 @@ namespace Twig\Util; */ final class ReflectionCallable { - private \ReflectionFunctionAbstract $reflector; - private \Closure|string|array|null $callable = null; - private string $name; + private $reflector; + private $callable = null; + private $name; public function __construct($callable, string $debugType = 'unknown', string $debugName = 'unknown') { @@ -74,7 +74,7 @@ final class ReflectionCallable return $this->reflector; } - public function getCallable(): \Closure|string|array|null + public function getCallable() { return $this->callable; }