Skip to content

PrivatizeFinalClassPropertyRector cause fatal error on set visibility property #9971

Open
rectorphp/rector-src
#8935

Description

@samsonasik

Bug Report

Subject Details
Rector version e.g. dev-main

Minimal PHP Code Causing Issue

Given the following code:

final class SomeClass
{
    protected protected(set) string $name = 'a';

    protected private(set) string $other = 'b';

    public function __construct(
        protected protected(set) int $promoted,
    ) {
    }
}

It cause change:

 <?php
 
 final class SomeClass
 {
-    protected protected(set) string $name = 'a';
+    private protected(set) string $name = 'a';
 
-    protected private(set) string $other = 'b';
+    private private(set) string $other = 'b';
 
     public function __construct(
-        protected protected(set) int $promoted,
+        private protected(set) int $promoted,
     ) {
     }
 }

which cause fatal error

Fatal error: Visibility of property SomeClass::$name must not be weaker than set visibility

Ref https://3v4l.org/5SltD#v8.5.10
Ref https://getrector.com/demo/3cdeaba7-1cec-48c5-9875-30bc7e726a93

Expected Behaviour

It should not error by change to private.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions