Skip to content

TernaryToNullCoalescingRector strips unrelated () and breaks the code #8910

Closed

Description

@zoliszabo

Hi there!

I found an edge case, where TernaryToNullCoalescingRector strips a set of () and breaks the code.

 $a = null;
 $b = 2;
-$m = isset($a) ? $a : ('R' . ($b == 1? '' : 'ector'));
+$m = $a ?? ('R' . $b == 1? '' : 'ector');
 var_dump($m);

The original version outputs:

string(6) "Rector"

while the proposed version:

string(5) "ector"

Config (rector.php):

<?php

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
    ->withSets([
        LevelSetList::UP_TO_PHP_84,
    ])
    // demonstrate specific PHP version
    ->withPhpVersion(PhpVersion::PHP_84);

Demo: https://getrector.com/demo/1f14af48-9e91-4a05-9822-a1c18048bd7e

Activity

  1. changed the title [-]TernaryToNullCoalescingRector strips `()` and breaks the code[/-] [+]TernaryToNullCoalescingRector strips unrelated `()` and breaks the code[/+] on Nov 2, 2026
  2. samsonasik commented on Nov 4, 2026

    @samsonasik
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions