> Le 5 août 2022 à 19:08, Larry Garfield <la...@garfieldtech.com> a écrit :
> 
> Ilija Tovilo and I are happy to present the first new RFC for PHP 8.3: 
> Asymmetric Visibility.
> 
> https://wiki.php.net/rfc/asymmetric-visibility
> 
> Details are in the RFC, but it's largely a copy of Swift's support for the 
> same.
> 
> -- 
>  Larry Garfield
>  la...@garfieldtech.com
> 

Hi,

I like the RFC, and in particular allowing property visibility to remain 
orthogonal to property accessors.

There are few missing details in the RFC (which is otherwise good):

1. Are static properties supported?

2. What about properties that are overridden/redeclared in a subclass? Given 
that extending the visibility is generally allowed:

```php
class A { 
        protected int $x;
}
class B extends A {
        public int $x; // ok
}
```

I expect that the following should be allowed as well:

```php
class A { 
        public protected(set) int $x;
}
class B extends A {
        public int $x; // ok
}
```

On the other hand, I expect that the two following cases should *not* be 
allowed, because it would break encapsulation of class A:

```php
class A { 
        public private(set) int $x;
}
class B extends A {
        public int $x; // error: cannot change a private property to public (or 
protected)
}
```

and:

```php
class A { 
        public private(set) int $x;
}
class B extends A {
        public private(set) int $x; // error: cannot make a private property in 
A as private in B
}
```

—Claude

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to