Symfony
Read post

New in Twig 4.0: A New Macro System (Symfony Blog)

Twig 4.0 overhauls the macro system to make it strict and consistent with how functions and filters work. Key changes include: required arguments (unless a default is declared), explicit variadic arguments using `...` notation instead of the implicit `varargs` magic variable, mandatory parentheses when calling macros, and case-sensitive macro names. Previously, macros silently swallowed typos, missing arguments, and extra arguments — all of which now produce clear error messages. Additional improvements include dynamic macro names (available since Twig 3.28) and a `deprecated` tag for macro libraries. A smooth upgrade path exists via Twig 3.29, which triggers deprecation warnings for all patterns that will break in 4.0.

    #php#symfony
Today•6m read time•From symfony.com
Post cover image
Table of contents
The Problem: Macros Are Too ForgivingRequired ArgumentsExplicit Variadic ArgumentsCalls Look Like CallsClear Errors Instead of Broken OutputA More Capable Macro ToolboxThe Upgrade Path
7.4K Impressions
Symfony's image
Symfony

The Symfony Blog provides updates, tutorials, and insights on Symfony, a popular PHP framework for b...

607 Followers

•

1.1K Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard