Re: [RFC] Readonly Properties
| From: | Andrea Faulds | Date: | Thu, 30 Oct 2014 01:35:41 +0000 |
| Subject: | Re: [RFC] Readonly Properties | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78448@lists.php.net to get a copy of this message | ||
> On 29 Oct 2014, at 04:29, Jordi Boggiano <j.boggiano@seld.be> wrote:
>
> Yup that's definitely better than having the readonly flag in the {} block as I had it.
>
> I'd however say that it should be possible to define a writable property with only a
> getter and then the setter would implicitly be created. Since readonly is the way to define
> writability why should I have to specify a setter (even a default empty one) if none is needed?
>
> P.S: Don't want to open pandora's box, but we could also have writeonly for
> completeness perhaps. I don't really see the use case at all though (immutability sure, mutant
> bottomless pit objects not so much:).
I don’t think allowing write-only properties is a good idea if we need a new keyword for it.
To be honest, for such a use case, using a setter method is probably better than assigning as if it
were a normal property. While people would probably tolerate and understand read-only (from their
perspective outside the class) properties, I think write-only properties will just lead to poor API
design and confusion.
--
Andrea Faulds
http://ajf.me/