-
Notifications
You must be signed in to change notification settings - Fork 8k
Open
Labels
Description
Description
The following code results in a PHP Fatal Error:
trait FooTrait
{
private array $options = [];
}
class Foo
{
use FooTrait;
public function __construct(private array $options = []) {}
}
The error thrown is
PHP Fatal error: Foo and FooTrait define the same property ($options) in the composition of Foo. However, the definition differs and is considered incompatible.
However, the same thing defined in the class instead of in the constructor works:
trait FooTrait
{
private array $options = [];
}
class Foo
{
use FooTrait;
private array $options = [];
}
As does the same thing, but without setting a default value:
trait FooTrait
{
private array $options;
}
class Foo
{
use FooTrait;
public function __construct(private array $options) {}
}
This seems to be ane rror
PHP Version
PHP 8.1.29 to PHP 8.4.0-dev
Operating System
MAC OSX 14.7