Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for readonly classes implementing an interface property #87

Closed
iluuu1994 opened this issue May 16, 2023 · 2 comments
Closed

Add test for readonly classes implementing an interface property #87

iluuu1994 opened this issue May 16, 2023 · 2 comments
Assignees

Comments

@iluuu1994
Copy link
Owner

iluuu1994 commented May 16, 2023

cf: https://www.reddit.com/r/PHP/comments/13camsm/comment/jjljmqd/

@iluuu1994
Copy link
Owner Author

iluuu1994 commented May 16, 2023

We should add a test to confirm this, but I believe what would happen is a readonly class may implement an interface with properties, as long as it satisfies those properties with basic properties that have no hooks. So, this should be fine:

interface I {
    public string $name { get; }
}

readonly class R implements I {
    public function __construct(public string $name) {}
}

That's not what currently happens. Every property in a readonly class becomes implicitly readonly. However, non-readonly properties may not be re-declared as readonly. If it's simple enough, it makes sense to relax this restriction.

Fatal error: Cannot redeclare non-readonly property I::$name as readonly R::$name

@Crell
Copy link
Collaborator

Crell commented May 16, 2023

Hrm, interesting. I would also favor relaxing that restriction here if possible. It seems like a reasonable use case.

@Crell Crell changed the title Add test for readonly classes implementing an interface property, cf: https://www.reddit.com/r/PHP/comments/13camsm/comment/jjljmqd/ Add test for readonly classes implementing an interface property May 16, 2023
@iluuu1994 iluuu1994 pinned this issue Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

2 participants