diff --git a/src/Extension/CoreExtension.php b/src/Extension/CoreExtension.php index d114e6cf2c4..e3243a5e1ec 100644 --- a/src/Extension/CoreExtension.php +++ b/src/Extension/CoreExtension.php @@ -251,7 +251,7 @@ public function getTests(): array new TwigTest('divisible by', null, ['node_class' => DivisiblebyTest::class, 'one_mandatory_argument' => true]), new TwigTest('constant', null, ['node_class' => ConstantTest::class]), new TwigTest('empty', 'twig_test_empty'), - new TwigTest('iterable', 'twig_test_iterable'), + new TwigTest('iterable', 'is_iterable'), ]; } @@ -392,7 +392,7 @@ function twig_random(Environment $env, $values = null, $max = null) } } - if (!twig_test_iterable($values)) { + if (!is_iterable($values)) { return $values; } @@ -529,7 +529,7 @@ function twig_date_converter(Environment $env, $date = null, $timezone = null) */ function twig_replace_filter($str, $from) { - if (!twig_test_iterable($from)) { + if (!is_iterable($from)) { throw new RuntimeError(sprintf('The "replace" filter expects an array or "Traversable" as replace values, got "%s".', \is_object($from) ? \get_class($from) : \gettype($from))); } @@ -626,7 +626,7 @@ function twig_array_merge(...$arrays) $result = []; foreach ($arrays as $argNumber => $array) { - if (!twig_test_iterable($array)) { + if (!is_iterable($array)) { throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" for argument %d.', \gettype($array), $argNumber + 1)); } @@ -722,7 +722,7 @@ function twig_last(Environment $env, $item) */ function twig_join_filter($value, $glue = '', $and = null) { - if (!twig_test_iterable($value)) { + if (!is_iterable($value)) { $value = (array) $value; } @@ -1428,7 +1428,7 @@ function twig_constant_is_defined($constant, $object = null) */ function twig_array_batch($items, $size, $fill = null, $preserveKeys = true) { - if (!twig_test_iterable($items)) { + if (!is_iterable($items)) { throw new RuntimeError(sprintf('The "batch" filter expects an array or "Traversable", got "%s".', \is_object($items) ? \get_class($items) : \gettype($items))); } @@ -1672,7 +1672,7 @@ function twig_array_column($array, $name, $index = null): array function twig_array_filter(Environment $env, $array, $arrow) { - if (!twig_test_iterable($array)) { + if (!is_iterable($array)) { throw new RuntimeError(sprintf('The "filter" filter expects an array or "Traversable", got "%s".', \is_object($array) ? \get_class($array) : \gettype($array))); } diff --git a/src/Node/WithNode.php b/src/Node/WithNode.php index 56a334496e9..2ac9123d0d1 100644 --- a/src/Node/WithNode.php +++ b/src/Node/WithNode.php @@ -45,7 +45,7 @@ public function compile(Compiler $compiler): void ->write(sprintf('$%s = ', $varsName)) ->subcompile($node) ->raw(";\n") - ->write(sprintf("if (!twig_test_iterable(\$%s)) {\n", $varsName)) + ->write(sprintf("if (!is_iterable(\$%s)) {\n", $varsName)) ->indent() ->write("throw new RuntimeError('Variables passed to the \"with\" tag must be a hash.', ") ->repr($node->getTemplateLine())