Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78404 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90212 invoked from network); 27 Oct 2014 20:27:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Oct 2014 20:27:39 -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.216 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 192.64.116.216 imap10-3.ox.privateemail.com Received: from [192.64.116.216] ([192.64.116.216:59001] helo=imap10-3.ox.privateemail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 06/66-56216-ABAAE445 for ; Mon, 27 Oct 2014 15:27:38 -0500 Received: from localhost (localhost [127.0.0.1]) by mail.privateemail.com (Postfix) with ESMTP id E44CD2400C2; Mon, 27 Oct 2014 16:27:35 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at imap10.ox.privateemail.com Received: from mail.privateemail.com ([127.0.0.1]) by localhost (imap10.ox.privateemail.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Z8pKYHRGLo6L; Mon, 27 Oct 2014 16:27:35 -0400 (EDT) Received: from oa-res-26-28.wireless.abdn.ac.uk (oa-res-26-28.wireless.abdn.ac.uk [137.50.26.28]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.privateemail.com (Postfix) with ESMTPSA id 41FA82400DF; Mon, 27 Oct 2014 16:27:35 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.0 \(1990.1\)) In-Reply-To: <544D48A3.6070905@gmail.com> Date: Mon, 27 Oct 2014 20:27:33 +0000 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <572FEBD1-99A8-4788-83F9-D99E470FB16D@ajf.me> References: <6E04B9BE-854E-4112-8C74-7D90BD8BFE95@ajf.me> <544D48A3.6070905@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 26 Oct 2014, at 19:16, Rowan Collins = wrote: >=20 > I just had a thought on both the naming and future-proofing concerns = of this proposal: what about pre-emptively reserving the skeleton of the = syntax needed for accessors, without actually implementing them? I=E2=80=99ve been thinking about this. While `public readonly $foo;` = does work, it is confusing (only readonly to public) and limiting (no = public/private option). Plus, while it could work with getters/setters, = it=E2=80=99s hardly ideal. On the other hand, while having C#-style syntax here gives us a full = feature set, I don=E2=80=99t like that it inverts the order of a = declaration. To show you what I mean, here=E2=80=99s a normal property: public $foobar; Now, here=E2=80=99s a property with C#-style syntax: var $foobar { public get; private set; }; See how the `public` moved to the right? I don=E2=80=99t like that, I = want to avoid that if possible. I=E2=80=99m all for C#-style syntax with = the get and set, but I don=E2=80=99t like that it moves the visibility = specifier. Similarly, I don=E2=80=99t like this either: public $foobar { get; private set; } Now the visibility is on both sides! Yuck. That=E2=80=99s the worst of = both worlds. What I=E2=80=99d like is probably something like this: public/private $foobar; Tentative syntax. But this way, the visibility stays on the left. I = think that=E2=80=99s good for readability. If you omit the second = specifier, then the first one applies to getting and setting, as now. If = you include it, the first one applies to getting, the second one to = setting. It=E2=80=99d also be compatible with properties, too: public/private $foobar { get { return $this->bar * $this->foo; } set($value) { $this->bar =3D $value / $this->foo; } } It doesn=E2=80=99t prevent truly read-only properties, either: public $foobar { get { return $this->bar * $this->foo; } } Does this sound like a good idea? A similar idea came up in the = discussions 8 years ago on readonly. -- Andrea Faulds http://ajf.me/