Skip to content

Merge 2.3.x into 2.2.x - #6429

Closed
staabm wants to merge 4 commits into
phpstan:2.3.xfrom
staabm:m6418
Closed

Merge 2.3.x into 2.2.x#6429
staabm wants to merge 4 commits into
phpstan:2.3.xfrom
staabm:m6418

Conversation

@staabm

@staabm staabm commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

merge #6418 into 2.3.x

phpstan-bot and others added 4 commits September 12, 2026 18:24
…he right side has side effects

* `CoalesceExpressionNode` now also carries the `ExpressionResult` of the right
  operand, passed in by `CoalesceHandler` (`??`) and `AssignOpHandler` (`??=`).
* `NullCoalesceRule::checkUnnecessaryNullCoalesce()` only reports the coalesce as
  unnecessary when evaluating the right side cannot do anything besides producing
  its null value: no impure points, no explicit throw points, no yield and no
  assignment/increment inside it. This mirrors the criterion `ExpressionHandler`
  already uses to decide whether an expression statement is a noop.
* Both operators on the axis are covered: a call returning `null` on the right of
  `??` and on the right of `??=` are no longer reported. Probed and fixed for
  function calls, method calls, static calls, `__invoke()` and closure calls, plus
  plain assignments on the right side (`$a ?? $x = null`), which are not impure
  points but still change behaviour when the coalesce is deleted.
* Side-effect-free right sides (`null`, a `null` constant, a class constant, a
  `null` variable, a `null`-typed property read, a `@phpstan-pure` call) keep
  being reported.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The data file declared `null` return types natively, which is only a type
on PHP 8.2+. With a lower `phpVersion` (the tests run on PHP 7.4 too) the
same declaration resolves to an object type named `null`, so the right
side isn't null and the pure-function case wasn't reported.

Declare the null return types in PHPDoc instead so every case exercises
what it claims on all analysed PHP versions.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Only the plain `Assign` branch was exercised so far. Add one right side
per remaining node kind, each of them inferred as `null` so it reaches
the check: `=&`, a nested `+=`, and `++`/`--` in an array offset of an
`array<int, null>`.

Removing any single `instanceof` clause makes exactly one of these cases
report the false positive again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@staabm staabm changed the title merge 2.3.x into 2.2.x Merge 2.3.x into 2.2.x Sep 12, 2026
@phpstan-bot

Copy link
Copy Markdown
Collaborator

You've opened the pull request against the latest branch 2.3.x. PHPStan 2.3 is not going to be released for months. If your code is relevant on 2.2.x and you want it to be released sooner, please rebase your pull request and change its target to 2.2.x.

@staabm
staabm marked this pull request as ready for review September 12, 2026 19:09
@phpstan-bot

Copy link
Copy Markdown
Collaborator

This pull request has been marked as ready for review.

@staabm staabm closed this Sep 12, 2026
@staabm
staabm deleted the m6418 branch September 12, 2026 19:10
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.

2 participants