Skip to content

[CodingStyle] Deprecate NullableCompareToNullRector - #8268

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-nullable-compare-to-null
Aug 2, 2026
Merged

[CodingStyle] Deprecate NullableCompareToNullRector#8268
TomasVotruba merged 1 commit into
mainfrom
deprecate-nullable-compare-to-null

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Deprecates NullableCompareToNullRector.

The rule turns a truthy if check on a nullable object into an explicit !== null compare:

 /** @var stdClass|null $value */
-if ($value) {
+if ($value !== null) {
 }

-if (! $value) {
+if ($value === null) {
 }

The result is still a weak, ambiguous comparison. !== null only tells us "not null" — it says nothing about what the value actually is, and it silently keeps working when the type later widens to a union of more classes.

An instanceof check is stronger and self-documenting:

if ($value instanceof stdClass) {
}

That is what the instanceof rule set already provides, so this rule only competes with it while producing the weaker output.

Rule is removed from the coding style level set and now throws on use, in line with the other recent deprecations.

@TomasVotruba
TomasVotruba merged commit dce07db into main Aug 2, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-nullable-compare-to-null branch August 2, 2026 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant