On Fri, Oct 24, 2014 at 1:36 AM, Andrea Faulds <a...@ajf.me> wrote:

> Good evening once again,
>
> Here’s another RFC: https://wiki.php.net/rfc/readonly_properties
>
> It proposes, with a working implementation, a modifier for properties that
> makes them readable and writeable from different scopes.
>
> Since I am a big proponent of including specification patches in new RFCs,
> I have decided to put my money (or rather, time) where my mouth is and I
> have actually written a specification patch before writing an RFC. I would
> love to see this become the new standard for RFCs affecting the language.
>
> If you are curious at all about the behaviour, I suggest perusing the
> fairly comprehensive set of twelve tests included in the main patch to
> php-src.
>
> Thanks!
>

While I think the functionality behind this proposal is nice in principle,
I have two objections with the RFC:

1. It uses the "readonly" modifier, to refer to a property that is publicly
readable, but protectedly writable (or protectedly readable and privately
writable). This isn't entirely obvious from the term "readonly" and also
does not match the behavior of other languages employing a "readonly"
modifier, like C#. An additional complication may be encountered in the
case where the readonly property stores an object, in which case I presume
it will be possible to modify the stored object ($obj->readonlyProp->prop =
42), which is likely not expected "readonly" behavior.

2. If the aim of this RFC is to replace the getFoo() pattern with the use
of "readonly public $foo" properties, a primary difference will be that a
getFoo() method can be declared in an interface, whereas a "readonly public
$foo" property cannot be. Thus code making use of interfaces will not be
able to employ this feature. And I don't think that allowing properties in
interfaces is reasonable at this point, because the implementations will be
limited to simple-storage properties - only with more comprehensive
property accessor support would implementations be allowed to use more
complex backing code.

For these reasons I do not think this RFC is suitable for inclusion in PHP
in its current state. As others in this thread have already pointed out, it
may be advisable to reconsider readonly properties in the broader context
of property accessors.

Nikita

Reply via email to