Skip to content

PHP 8.4: allow Traits & Class defining same (compatible) properties #17812

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

Closed
procodix opened this issue Feb 15, 2025 · 2 comments
Closed

PHP 8.4: allow Traits & Class defining same (compatible) properties #17812

procodix opened this issue Feb 15, 2025 · 2 comments

Comments

@procodix
Copy link

Description

This is considered an error now, but should be possible, the same way it works with methods, so that also the new property hooks would work.

trait TestTrait {
	public int $Var = 1;
	public function Func():int {return 1;}
}

class TestClass {
	use TestTrait;
	
	public int $Var = 2; // this is not allowed
	public function Func():int {return 2;} // this is ok
}
@iluuu1994
Copy link
Member

iluuu1994 commented Feb 24, 2025

This is very long-standing behavior (https://3v4l.org/6uh6E), and it was part of the RFC.

https://wiki.php.net/rfc/horizontalreuse#handling_of_propertiesstate

Properties are considered incompatible if they differ in their definition. This means, they differ in the applied modifiers (static, public, protected, private) or their initial value.

I don't really see a technical reason why it needs to be this way, but since this was a community decision, changing it will require an RFC.

I understand that with hooks shadowing of trait properties becomes more reasonable. That said, I believe it's a complex enough topic to warrant an RFC. For example, it's unclear whether the shadowing property adopts unlisted hooks from the trait, or whether it needs to repeat the hook in full.

Copy link

There has not been any recent activity in this feature request. It will automatically be closed in 14 days if no further action is taken. Please see https://github.com/probot/stale#is-closing-stale-issues-really-a-good-idea to understand why we auto-close stale feature requests.

@github-actions github-actions bot added the Stale label May 26, 2025
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants