Make compatible with PHP<8

This commit is contained in:
Fabien Potencier
2024-07-14 12:08:28 +02:00
parent 093f51a8b9
commit bb967b3dd3
2 changed files with 10 additions and 6 deletions
+6 -2
View File
@@ -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;
}
}
+4 -4
View File
@@ -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;
}