Skip to content

[DeadCode] Skip RemoveParentDelegatingConstructorRector on protected parent constructor - #8309

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-remove-parent-delegating-constructor-protected-parent
Aug 6, 2026
Merged

[DeadCode] Skip RemoveParentDelegatingConstructorRector on protected parent constructor#8309
TomasVotruba merged 1 commit into
mainfrom
fix-remove-parent-delegating-constructor-protected-parent

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Aug 6, 2026

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9842

The rule checked that the child constructor is public, but never checked the parent's visibility. Removing a public constructor that delegates to a protected parent one silently narrows visibility and breaks instantiation:

Fatal error: Uncaught Error: Call to protected A::__construct() from global scope

Buggy behavior before this PR:

 class A
 {
     protected function __construct($value)
     {
     }
 }

 class B extends A
 {
-    public function __construct($value)
-    {
-        parent::__construct($value);
-    }
 }

 new B('value'); // fatal error after the change

Now the rule bails out when the parent constructor is not public, so the code above is left untouched.

@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 6, 2026 14:11
@TomasVotruba
TomasVotruba force-pushed the fix-remove-parent-delegating-constructor-protected-parent branch from 9e4c1a6 to b25a22b Compare August 6, 2026 14:14
@TomasVotruba
TomasVotruba merged commit 966b50d into main Aug 6, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the fix-remove-parent-delegating-constructor-protected-parent branch August 6, 2026 14:15
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.

Incorrect behavior of RemoveParentDelegatingConstructorRector

1 participant