Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78431 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67634 invoked from network); 28 Oct 2014 15:08:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Oct 2014 15:08:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 192.64.116.208 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.208 imap2-3.ox.privateemail.com Received: from [192.64.116.208] ([192.64.116.208:54439] helo=imap2-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BF/67-21571-161BF445 for ; Tue, 28 Oct 2014 10:08:18 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id 0FA638C0084; Tue, 28 Oct 2014 11:08:15 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap2.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap2.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 05Dm7kmQNRKt; Tue, 28 Oct 2014 11:08:14 -0400 (EDT) Received: from oa-edu-168-194.wireless.abdn.ac.uk (oa-edu-168-194.wireless.abdn.ac.uk [137.50.168.194]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 3F6568C0082; Tue, 28 Oct 2014 11:08:14 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) In-Reply-To: <544FA716.2030508@gmail.com> Date: Tue, 28 Oct 2014 15:08:11 +0000 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: <6E04B9BE-854E-4112-8C74-7D90BD8BFE95@ajf.me> <544D48A3.6070905@gmail.com> <572FEBD1-99A8-4788-83F9-D99E470FB16D@ajf.me> <544F4321.8040302@seld.be> <544FA716.2030508@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.1990.1) Subject: Re: [PHP-DEV] [RFC] Readonly Properties From: ajf@ajf.me (Andrea Faulds) > On 28 Oct 2014, at 14:24, Rowan Collins = wrote: >=20 > Andrea Faulds wrote on 28/10/2014 14:08: >>> >On 28 Oct 2014, at 07:17, Jordi Boggiano = 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? >> Well, no. If you choose to specify getters and setters, and only = specify a setter, of course it is read-only. It doesn=E2=80=99t make = sense to have a getter and no setter and yet expect a property to be = writeable. >>=20 >=20 > 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. 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. -- Andrea Faulds http://ajf.me/