Skip to content

[remove] Remove deprecated NewInInitializerRector - #8328

Merged
TomasVotruba merged 1 commit into
mainfrom
remove-new-in-initializer-rector
Aug 9, 2026
Merged

[remove] Remove deprecated NewInInitializerRector#8328
TomasVotruba merged 1 commit into
mainfrom
remove-new-in-initializer-rector

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Removes NewInInitializerRector, deprecated since 2026-04 in #7913. Follows the same cleanup as #8094.

The rule collapsed an optional dependency into a promoted property with a new default:

 class SomeClass
 {
-    private Logger $logger;
-
     public function __construct(
-        ?Logger $logger = null,
+        private ?Logger $logger = new NullLogger,
     ) {
-        $this->logger = $logger ?? new NullLogger;
     }
 }

The two forms are not equivalent. A default value applies only when the argument is omitted, so an explicit null still lands as null:

new SomeClass(null);
// before: $this->logger is NullLogger  (?? catches it)
// after:  $this->logger is null        (default never fires)

The property could never hold null before and can now, and Rector cannot see whether any caller passes null explicitly. That is the "depends on context" from the original deprecation.

It took six rounds of edge-case patching before it was given up on: #1737, #1740, #5971, #6599, #7545, #7546.

The rule was in no set and its tests were already removed with the deprecation, so this only drops the class plus its two now-obsolete phpstan.neon ignore entries.

Deprecated since 2026-04 in #7913. The rewrite is not equivalent: a promoted default only applies when the argument is omitted, so an explicit null argument lands as null instead of the coalesced fallback object.
@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 9, 2026 16:22
@TomasVotruba
TomasVotruba merged commit 6a7bd95 into main Aug 9, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the remove-new-in-initializer-rector branch August 9, 2026 16:23
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