Merge 2.3.x into 2.2.x - #6429
Closed
staabm wants to merge 4 commits into
Closed
Conversation
…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>
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
marked this pull request as ready for review
September 12, 2026 19:09
Collaborator
|
This pull request has been marked as ready for review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
merge #6418 into 2.3.x