Re: [RFC] Readonly Properties
| From: | Jordi Boggiano | Date: | Wed, 29 Oct 2014 04:29:20 +0000 |
| Subject: | Re: [RFC] Readonly Properties | ||
| References: | 1 2 3 4 5 6 7 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-78440@lists.php.net to get a copy of this message | ||
On 28/10/2014 15:08, Andrea Faulds 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:). Cheers -- Jordi Boggiano @seldaek - http://nelm.io/jordiOn 28 Oct 2014, at 14:24, Rowan Collins <rowan.collins@gmail.com> wrote: Andrea Faulds wrote on 28/10/2014 14:08:Hmm. Perhaps we need this, then: public $foobar; // public read, private write public/private $foobar; // public read, private write public readonly $foobar; // public read, not writeable at all This then confined set/get entirely to implementation details. A read-only property would be denoted by readonly. With the last one, you can only have get, for the first two, you must have both get and set. Does that work? Seems pretty good to me.I think the problem is that the get and set annotations are serving multiple purposes - to change the visibility, to define custom accessor/mutator code, but also to declare whether certain actions are possible at all. Since the default is for the property to be readable and writable, the fact that adding "{ get; }" makes it readonly isn't immediately intuitive, although it does makes sense once you think about it.Well, no. If you choose to specify getters and setters, and only specify a setter, of course it is read-only. It doesn’t make sense to have a getter and no setter and yet expect a property to be writeable.On 28 Oct 2014, at 07:17, Jordi Boggiano<j.boggiano@seld.be> wrote: I like it, except for the fact that if you add a custom getter to a property suddenly it becomes readonly unless you remember to add "; set" to the end of the block, right?