Skip to content

Fix the default filter fallback reusing a null-safe temporary variable - #4915

Merged
fabpot merged 3 commits into
twigphp:3.xfrom
lazerg:fix/issue-4914-default-null-safe
Sep 3, 2026
Merged

Fix the default filter fallback reusing a null-safe temporary variable#4915
fabpot merged 3 commits into
twigphp:3.xfrom
lazerg:fix/issue-4914-default-null-safe

Conversation

@lazerg

@lazerg lazerg commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

The default filter reuses the fallback argument node in both branches of the conditional it compiles to. Because GetAttrExpression records the temporary variable it allocated for a null-safe chain on the node itself, the second compilation skipped the assignment and emitted a bare $_vN reference, so {{ item?.label|default(item?.name) }} warned about an undefined variable whenever item was null.

The fallback node is now cloned, like the node used for the defined test already is, so each branch compiles its own temporary.

Fixes #4914

@lazerg
lazerg force-pushed the fix/issue-4914-default-null-safe branch from 2616498 to 86c830e Compare September 1, 2026 11:06
@fabpot

fabpot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Thank you @lazerg.

@fabpot
fabpot merged commit cb80d7a into twigphp:3.x Sep 3, 2026
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.

Undefined variable $_vN when chaining the null-safe operator (?.) with the default() filter and the object is null

2 participants