Skip to content

Commit 8afa951

Browse files
authored
[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.
1 parent 2ae6014 commit 8afa951

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

console/lockable_trait.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ a ``$lockFactory`` property with your own lock factory::
5555
{
5656
use LockableTrait;
5757

58-
public function __construct(private LockFactory $lockFactory)
58+
public function __construct(LockFactory $lockFactory)
5959
{
60+
$this->lockFactory = $lockFactory;
61+
62+
parent::__construct();
6063
}
6164

6265
// ...

0 commit comments

Comments
 (0)