Repository navigation
Conversation
Twig 3.31 traverses nodes through Node::getNodes() instead of iterating the node. The decorator delegated getIterator() but not the new method, so getNodes() returned the decorator's own, never initialized $nodes and compiling any template failed with: Twig\Node\Node::getNodes(): Return value must be of type array, null returned.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Twig 3.31.0 (2026-11-23) changed
NodeTraverserto walk child nodes through the newNode::getNodes()instead of iterating the node:GetAttrExpressionDecoratordoes not call the parent constructor and delegates everyNodemethod to the decoratedGetAttrExpression, includinggetIterator().getNodes()did not exist when the decorator was written, so it is not delegated. Twig's own implementation returns the decorator's$nodes, which is never initialized, and every template compilation fails:We hit it on a Media Site based project (Ibexa 5.0.11, Site API 7.0.3) as soon as Composer pulled
twig/twig3.31.1:cache:clearfails while warming up the Twig cache, and so does every page.Fix
Delegate
getNodes()to the decorated expression, the same waygetIterator()already is. On Twig below 3.31 nothing calls the method, so it changes nothing there.Tests
GetAttrExpressionDecoratorTestis new. It covers:getNodes()returns the nodes of the decorated expression (skipped on Twig below 3.31, whereNode::getNodes()does not exist)NodeTraverservisits the decorator and the nodes of the decorated expression without an errorI could not run the test suite locally. I checked the change end to end on the project instead: with Twig 3.31.1,
cache:clearfailed with the error above before the change and passed after it.🤖 Generated with Claude Code