From b1c9faa33e5e1d392664783eff47934f553efcb2 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 21 Oct 2020 14:08:16 +0200 Subject: [PATCH] Fix PHP 8 support --- doc/functions/range.rst | 4 ++-- src/Node/Expression/CallExpression.php | 11 ++++++++++- tests/Fixtures/functions/range.test | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/doc/functions/range.rst b/doc/functions/range.rst index 22de4df86..a1f0e7c09 100644 --- a/doc/functions/range.rst +++ b/doc/functions/range.rst @@ -51,8 +51,8 @@ function (with a step of ``1``, or ``-1`` if the start is greater than the end): Arguments --------- -* ``start``: The first value of the sequence. -* ``end``: The highest possible value of the sequence. +* ``low``: The first value of the sequence. +* ``high``: The highest possible value of the sequence. * ``step``: The increment between elements of the sequence. .. _`range`: https://secure.php.net/range diff --git a/src/Node/Expression/CallExpression.php b/src/Node/Expression/CallExpression.php index 0459dae08..d0667379d 100644 --- a/src/Node/Expression/CallExpression.php +++ b/src/Node/Expression/CallExpression.php @@ -149,7 +149,16 @@ abstract class CallExpression extends AbstractExpression $optionalArguments = []; $pos = 0; foreach ($callableParameters as $callableParameter) { - $names[] = $name = $this->normalizeName($callableParameter->name); + $name = $this->normalizeName($callableParameter->name); + if (\PHP_VERSION_ID >= 80000 && 'range' === $callable) { + if ('start' === $name) { + $name = 'low'; + } elseif ('end' === $name) { + $name = 'high'; + } + } + + $names[] = $name; if (\array_key_exists($name, $parameters)) { if (\array_key_exists($pos, $parameters)) { diff --git a/tests/Fixtures/functions/range.test b/tests/Fixtures/functions/range.test index bfacbe53d..2927333b9 100644 --- a/tests/Fixtures/functions/range.test +++ b/tests/Fixtures/functions/range.test @@ -1,7 +1,7 @@ --TEST-- "range" function --TEMPLATE-- -{{ range(start=0+1, end=10+0, step=2)|join(',') }} +{{ range(low=0+1, high=10+0, step=2)|join(',') }} --DATA-- return [] --EXPECT--