Skip to content

Commit fa8ff31

Browse files
committed
minor #21507 [Console][LockableTrait] Do not redeclare $lockFactory through constructor property promotion in the code example (nicuserban)
This PR was merged into the 7.3 branch. Discussion ---------- [Console][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. <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `7.x` for features of unreleased versions). --> Commits ------- 8afa951 [LockableTrait]Do not redeclare $lockFactory through constructor property promotion in the code example
2 parents 4468b2b + 8afa951 commit fa8ff31

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)