Open
Description
RFC - https://wiki.php.net/rfc/asymmetric-visibility-v2
- classic
class Foo
{
public private(set) string $bar = 'baz';
}
- property promotion
class Foo
{
public function __construct(
public private(set) string $bar,
) {}
}
- abbreviated form
public private(set) string $foo;
private(set) string $foo;
public protected(set) string $foo;
protected(set) string $foo;
- relation with readonly
// These create a public-read, protected-write, write-once property.
public protected(set) readonly string $foo;
public readonly string $foo;
readonly string $foo;
// These creates a public-read, private-set, write-once, final property.
public private(set) readonly string $foo;
private(set) readonly string $foo;
// These create a public-read, public-write, write-once property.
// While use cases for this configuration are likely few,
// there's no intrinsic reason it should be forbidden.
public public(set) readonly string $foo;
public(set) readonly string $foo;
// These create a private-read, private-write, write-once, final property.
private private(set) readonly string $foo;
private readonly string $foo;
// These create a protected-read, protected-write, write-once property.
protected protected(set) readonly string $foo;
protected readonly string $foo;
Metadata
Metadata
Assignees
Labels
No labels