Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Add a way to mark a `Twig\Markup` instance as safe for some escaping strategies only
* Make `Environment::getExtension()` return the runtime of an extension class registered with `AttributeExtension`
* Make `Environment::getRuntime()` fall back to the registered extension of the same class
* Speed up the `merge` filter and the `include` and `embed` tags with variables

# 3.30.0 (2026-09-25)

Expand Down
10 changes: 6 additions & 4 deletions src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,17 +732,19 @@ public static function urlencode($url): string
*/
public static function merge(...$arrays): array
{
$result = [];

foreach ($arrays as $argNumber => $array) {
if (\is_array($array)) {
continue;
}

if (!is_iterable($array)) {
throw new RuntimeError(\sprintf('The "merge" filter expects a sequence or a mapping, got "%s" for argument %d.', get_debug_type($array), $argNumber + 1));
}

$result = array_merge($result, self::toArray($array));
$arrays[$argNumber] = self::toArray($array);
}

return $result;
return array_merge(...$arrays);
}

/**
Expand Down
Loading