Skip to content

Update ondrejmirtes/simple-downgrader to 2.4.0, use ?-> where possible - #7043

Merged
ondrejmirtes merged 4 commits into
2.3.xfrom
bump-simple-downgrader-2.4.0
Nov 12, 2026
Merged

ondrejmirtes merged 4 commits into
2.3.xfrom
bump-simple-downgrader-2.4.0

Conversation

@ondrejmirtes

@ondrejmirtes ondrejmirtes commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

simple-downgrader 2.4.0 downgrades the nullsafe operator ?-> for PHP < 8.0, so it can be used in phpstan-src.

$foo?->bar->baz?->doFoo()
// becomes
$foo !== null ? ($nullsafeVariable1 = $foo->bar->baz) !== null ? $nullsafeVariable1->doFoo() : null : null

The rest of the chain is short-circuited like in PHP, non-variable bases are evaluated once, and isset(), empty() and ?? keep their no-warning semantics.

Using ?-> in phpstan-src

New build rule PHPStan\Build\NullsafeOperatorRule (identifier phpstan.nullsafeOperator, fixable) reports:

  • $a !== null ? $a->b()->c : null and $a === null ? null : $a->b() → $a?->b()->c
  • if ($a !== null) { $a->b(); } without else → $a?->b();

It only reports when $a is a variable, a property fetch or a static property fetch, so the replacement doesn't change how many times anything is called. It skips first-class callables, which can't be nullsafe. When the call's arguments span several lines, the error isn't fixable, because the printer would put them on one line.

phpstan --fix replaced the 150 places it found in 68 files. I removed redundant parentheses left around a few of them, such as ?? ($a?->b()). FixerApplication uses $this->fixerEncoder?->write() again instead of the writeToFixer() helper from edbc256.

I left out $a instanceof Foo ? $a->b() : null. In phpstan-src these narrow between types, such as Identifier|Name, rather than check for null.

I downgraded the result to PHP 7.4 with compiler/vendor/bin/simple-downgrade. No ?-> remained, and every downgraded file passes php -l.

2.4.0 downgrades the nullsafe operator ?-> for PHP < 8.0, so it can be
used in phpstan-src.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1cf65-c8c9-76e6-a6c6-639c9057ca36
… property fetch

Reports $a !== null ? $a->b() : null (and the === null form) and
if ($a !== null) { $a->b(); }, when $a is a variable or a property fetch
that can be evaluated twice. The 150 places it found were fixed with
phpstan --fix. ondrejmirtes/simple-downgrader 2.4.0 downgrades ?-> for
PHP 7.4.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1cf65-c8c9-76e6-a6c6-639c9057ca36
simple-downgrader 2.4.0 downgrades it, so the writeToFixer() helper
added in edbc256 is no longer needed.

Amp-Thread-ID: https://ampcode.com/threads/T-01a1cf65-c8c9-76e6-a6c6-639c9057ca36
@ondrejmirtes ondrejmirtes changed the title Update ondrejmirtes/simple-downgrader to 2.4.0 Update ondrejmirtes/simple-downgrader to 2.4.0, use ?-> where possible Nov 12, 2026
@ondrejmirtes
ondrejmirtes merged commit c588ead into 2.3.x Nov 12, 2026
446 of 448 checks passed
@ondrejmirtes
ondrejmirtes deleted the bump-simple-downgrader-2.4.0 branch November 12, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant