Skip to content

Conversation

@nicuserban
Copy link
Contributor

Adding visibility on the constructor parameter results in constructor property promotion and in redeclaring the property in a way which is incompatible with the declaration from the trait, resulting in a fatal error if the example is used as is. For reference: https://www.php.net/manual/en/language.oop5.traits.php#language.oop5.traits.properties.example
Instead, I think the visibility should be removed in order to prevent redeclaration (and incompatibility with the property from the trait), and just use dependency injection and overwrite the default value so that the trait won't create a new instance for the $lockFactory.

…erty promotion in the code example

Adding visibility on the constructor parameter results in constructor property promotion and in redeclaring the property in a way which is incompatible with the declaration from the trait, resulting in a fatal error if the example is used as is.
For reference: https://www.php.net/manual/en/language.oop5.traits.php#language.oop5.traits.properties.example
Instead, I think the visibility should be removed in order to prevent redeclaration (and incompatibility with the property from the trait), and just use dependency injection and overwrite the default value so that the trait won't create a new instance for the $lockFactory.
@carsonbot carsonbot changed the title [LockableTrait]Do not redeclare $lockFactory through constructor property promotion in the code example [LockableTrait] Do not redeclare $lockFactory through constructor property promotion in the code example Oct 16, 2025
@carsonbot carsonbot changed the title [LockableTrait] Do not redeclare $lockFactory through constructor property promotion in the code example [Console][LockableTrait] Do not redeclare $lockFactory through constructor property promotion in the code example Oct 17, 2025
@javiereguiluz javiereguiluz merged commit fa8ff31 into symfony:7.3 Oct 17, 2025
3 checks passed
@javiereguiluz
Copy link
Member

Good catch Nicolae 👏 and perfectly explained in the PR desription. Thanks for fixing this.

@nicuserban
Copy link
Contributor Author

nicuserban commented Oct 17, 2025

Good catch Nicolae 👏 and perfectly explained in the PR desription. Thanks for fixing this.

Thank you for your review and for merging this PR, Javier!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants