Skip to content

Deprecate duplicate macro definitions - #4873

Merged
fabpot merged 1 commit into
twigphp:3.xfrom
fabpot:deprecate-duplicate-macro-definitions
Jul 27, 2026
Merged

Deprecate duplicate macro definitions#4873
fabpot merged 1 commit into
twigphp:3.xfrom
fabpot:deprecate-duplicate-macro-definitions

Conversation

@fabpot

@fabpot fabpot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@upsun-dispatch

Copy link
Copy Markdown

📋 PR Summary

This PR deprecates defining a macro more than once in the same template. Parser::setMacro() now emits a trigger_deprecation notice (targeting Twig 4.0, where it will become a SyntaxError) when a macro name is already registered, and the change is documented in the CHANGELOG, the deprecation guide, and a new legacy integration test.

Changes
Layer / File(s) Summary
parser
src/Parser.php Adds a deprecation notice in setMacro() when a macro name is defined more than once, reporting both the first and second definition lines.
docs
CHANGELOG Adds a changelog entry for the new deprecation.
doc/deprecated.rst Documents the macro redefinition deprecation under a new Macros section.
tests
tests/Fixtures/macros/duplicate_definition.legacy.test Adds a legacy integration test asserting the deprecation message and that the last macro definition wins.

@fabpot
fabpot merged commit 44f6f7e into twigphp:3.x Jul 27, 2026
54 checks passed
@fabpot
fabpot deleted the deprecate-duplicate-macro-definitions branch July 27, 2026 10:45
Comment thread src/Parser.php
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