Skip to content

Redesign macro calls and argument handling#4851

Open
fabpot wants to merge 1 commit into
twigphp:3.xfrom
fabpot:macro-ng
Open

Redesign macro calls and argument handling#4851
fabpot wants to merge 1 commit into
twigphp:3.xfrom
fabpot:macro-ng

Conversation

@fabpot

@fabpot fabpot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

This is my attempt to make macros "better". It uses modern PHP features that didn't exist when I designed macros a long time ago.

The first objective is to close the gap between their behavior and the behavior of Twig callables: functions, filters, and tests.

Here are some important changes:

  • Calling a macro without passing a value for an argument that has no default value is deprecated; it is currently silently passed as null.
  • Passing extra positional arguments or unknown named arguments to a macro without an explicit variadic argument is deprecated; these arguments are currently silently accepted through the implicit varargs variable.
  • Explicit variadic macro arguments are now supported with ...name.
  • Macros are compiled as closures stored in the macro registry, instead of public generated macro_* methods.

The refactor introduces TwigMacro and MacroArgument to represent template-defined macros with an explicit signature, similar to the existing Twig callable model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant