From 8afa951be5ecbb3171d2469bd1a9fc51980527fc Mon Sep 17 00:00:00 2001 From: Nicolae Serban Date: Thu, 16 Oct 2025 23:47:13 +0300 Subject: [PATCH] [LockableTrait]Do not redeclare $lockFactory through constructor property 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. --- console/lockable_trait.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/console/lockable_trait.rst b/console/lockable_trait.rst index 2a4fd64ffaf..8325e1f09b6 100644 --- a/console/lockable_trait.rst +++ b/console/lockable_trait.rst @@ -55,8 +55,11 @@ a ``$lockFactory`` property with your own lock factory:: { use LockableTrait; - public function __construct(private LockFactory $lockFactory) + public function __construct(LockFactory $lockFactory) { + $this->lockFactory = $lockFactory; + + parent::__construct(); } // ...