Skip to content

8.4 - Asymmetric Visibility #1144

Open
Open
@genintho

Description

@genintho

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions