Skip to content

[Privatization] Remove final flag on Privatize*Rector from protected to private - #8509

Merged
TomasVotruba merged 1 commit into
mainfrom
remove-final-protected-to-private
Sep 21, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
remove-final-protected-to-private

Conversation

@samsonasik

@samsonasik samsonasik commented Sep 20, 2026

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9908

On PHP 8.4, protected final is allowed, while private final is forbidden

see https://3v4l.org/gXaQt#v8.4.25 vs https://3v4l.org/lhT8c#v8.4.25

so final flag need to be removed when change protected to private, except __construct() which allowed.

@samsonasik

Copy link
Copy Markdown
Member Author

@TomasVotruba ready 👍

@samsonasik
samsonasik force-pushed the remove-final-protected-to-private branch from 3269ce9 to c4ea6b6 Compare September 21, 2026 06:04
@samsonasik

Copy link
Copy Markdown
Member Author

@TomasVotruba rebased ready for merge 👍

@TomasVotruba

Copy link
Copy Markdown
Member

Title and description needs an update

@TomasVotruba

Copy link
Copy Markdown
Member

Can you squash it to one?
Maybe better target would be PHP 8.4 if this crashes on PHP 8.5. What fo you think?

@samsonasik samsonasik changed the title [Privatization] Remove final flag on PrivatizeFinalClassPropertyRector, PrivatizeFinalClassConstantRector, PrivatizeFinalClassMethodRector [Privatization] Remove final flag on Privatize*Rector from protected to private Sep 21, 2026
@samsonasik

Copy link
Copy Markdown
Member Author

I've updated title.

The output on 3v4l.org is since php 8.4

Before

Screenshot 2026-09-21 at 14 04 27

After

When changed protected to private without removing final:

Screenshot 2026-09-21 at 14 04 35

what do you mean for squash, the commit squashed on merge

@TomasVotruba

Copy link
Copy Markdown
Member

Squash to 1 commit here, so its more readable. Once done.

Also, I meant a new PHP 8.4 rule that would handle this on its own. Outside privatization set compleetely.

@samsonasik
samsonasik force-pushed the remove-final-protected-to-private branch from 65bdc10 to 4eb2d24 Compare September 21, 2026 07:10
@samsonasik

Copy link
Copy Markdown
Member Author

@TomasVotruba sure, squashed 👍

@samsonasik

Copy link
Copy Markdown
Member Author

On PHP < 8.4, it not support protected final yet, not sure what kind of new rule needed because that already too early error.

@TomasVotruba

Copy link
Copy Markdown
Member

Ah, I see. So it's only invalid in here. Got it 👍

@TomasVotruba
TomasVotruba merged commit 1d0224b into main Sep 21, 2026
45 checks passed
@TomasVotruba

Copy link
Copy Markdown
Member

Thanks 👍

@TomasVotruba
TomasVotruba deleted the remove-final-protected-to-private branch September 21, 2026 07:26
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.

PrivatizeFinalClassPropertyRector cause invalid change on protected final modifier

2 participants