Skip to content

[Php70] Preserve fallback parentheses on Identical/NotIdentical path in TernaryToNullCoalescingRector - #8674

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-9912-ternary-null-coalesce-fallback-parentheses
Oct 16, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
fix-9912-ternary-null-coalesce-fallback-parentheses

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9912

$a !== null ? $a : ($b ? 'yes' : 'no') was rewritten to $a ?? $b ? 'yes' : 'no', dropping the parentheses around the nested ternary fallback. Since ?? binds tighter than ?:, the result parses as ($a ?? $b) ? 'yes' : 'no', changing semantics.

The isset() / is_null() paths already call preserveWrappedFallback(); the Identical / NotIdentical path did not. This adds that call on both branches.

Fixture covers both !== null and === null forms.

@TomasVotruba
TomasVotruba merged commit a069840 into main Oct 16, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the fix-9912-ternary-null-coalesce-fallback-parentheses branch October 16, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant