Skip to content

Redesign macro calls and argument handling - #4851

Merged
fabpot merged 1 commit into
twigphp:3.xfrom
fabpot:macro-ng
Jul 30, 2026
Merged

Redesign macro calls and argument handling#4851
fabpot merged 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.

Comment thread src/ExpressionParser/Infix/FunctionExpressionParser.php Outdated
Comment thread src/ExpressionParser/Infix/DotExpressionParser.php Outdated
Comment thread src/TokenParser/MacroTokenParser.php Outdated
Comment thread src/Template.php
Comment thread tests/Fixtures/macros/varargs.test
Comment thread tests/Fixtures/macros/simple.test
Comment thread src/TokenParser/FromTokenParser.php Outdated
@upsun-dispatch

upsun-dispatch Bot commented Jul 3, 2026

Copy link
Copy Markdown

📋 PR Summary

Table. deduplication.- **wait, I should alsoead only include, focus reviewers found. And the shim oneplication is real. Let me finalize., JSON output.en{{

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: full · 40 files reviewed · no issues found

Review details

Commit: Commit dd55a6e
Model: claude-opus-4-8
Panel: correctness · robustness · design

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: incremental · 42 files reviewed · no new issues

Review details

Commit: Commits dd55a6e..184ed57
Model: claude-opus-4-8
Panel: correctness · robustness · design

@fabpot

fabpot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor Author

@stof I think I've taken all your comments into account.

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: incremental · 42 files reviewed · no new issues

Review details

Commit: Commits 184ed57..11d236b
Model: claude-opus-4-8
Panel: correctness · robustness · design

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: incremental · 42 files reviewed · no new issues

Review details

Commit: Commits 11d236b..aca56e0
Model: claude-opus-4-8
Panel: correctness · robustness · design

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: incremental · 42 files reviewed · no new issues

Review details

Commit: Commits aca56e0..4ddb552
Model: claude-opus-4-8
Panel: correctness · robustness · design

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: incremental · 43 files reviewed · 🟡 1 warning

Review details

Commit: Commits 4ddb552..65d8615
Model: claude-opus-4-8
Panel: correctness · robustness · design

Comment thread src/Template.php Outdated

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: incremental · 43 files reviewed · no new issues

Review details

Commit: Commits 65d8615..a708108
Model: claude-opus-4-8
Panel: correctness · robustness · design

Comment thread src/Template.php Outdated
Comment thread doc/tags/macro.rst Outdated
Comment thread src/ExpressionParser/Infix/DotExpressionParser.php

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: incremental · 45 files reviewed · no new issues · 2 still open

Outstanding from earlier reviews:

  • #3524445781 — src/Template.php:528: Wrong version attribution misleads users about when a deprecation/feature landed.
  • #3656514451 — src/Template.php:543: Duplicated resolution logic risks the defined-test and call paths drifting apart on future edits.

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📋 Upsun Dispatch Review: full · 45 files reviewed · no issues found · 1 still open

Outstanding from earlier reviews:

  • #3656514451 — src/Template.php:543: Duplicated resolution logic risks the defined-test and call paths drifting apart on future edits.

Comment thread src/Node/MacroNode.php Outdated
Comment thread src/Parser.php
Comment thread tests/Fixtures/macros/implicit_optional_arguments.legacy.test
Comment thread tests/Fixtures/macros/varargs_implicit.legacy.test

@stof stof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good, but some tests are failing due to deprecations.

@fabpot
fabpot merged commit 6dfc796 into twigphp:3.x Jul 30, 2026
12 checks passed
@fabpot
fabpot deleted the macro-ng branch July 30, 2026 11:53
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.

2 participants