Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78416 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28163 invoked from network); 28 Oct 2014 07:23:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Oct 2014 07:23:10 -0000 Authentication-Results: pb1.pair.com smtp.mail=pierre.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pierre.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.41 as permitted sender) X-PHP-List-Original-Sender: pierre.php@gmail.com X-Host-Fingerprint: 209.85.216.41 mail-qa0-f41.google.com Received: from [209.85.216.41] ([209.85.216.41:46799] helo=mail-qa0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AF/D0-21571-D544F445 for ; Tue, 28 Oct 2014 02:23:09 -0500 Received: by mail-qa0-f41.google.com with SMTP id k15so47606qaq.14 for ; Tue, 28 Oct 2014 00:23:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=HG94lUIP8CBan/PFmXFym/SaCstI6FDguwlB4c41gIM=; b=Deemn3p+/eG3uAEKpx0khRnwBEnDmLcN+3gkYMzJ880rgyxxEaJwCKi9y/FdknvNmt Hv4ahiZ3+mhDwa+Kd1Et+wr9qQjRSgZujE/8FjWYtsGXRyxZi5EaZrQBPsF/UIXIaCBT v5r7OgEJ5ZWQJgHTtozJxWi56XH19pCJlJDSl+MNMgPEazXijaaXJ5wBaANutG5ZAagi rB6Z8oQ+6xZDZL852vWzLo+fzpklEVXWoWQw3MikggAa4Xsfed6O9N9GvW18ykpGrU+L edBpKoyyQTiK2D0j6R8RavSvG3TMFYPtCNJMJ/Lg1eqe982ye7zwVjiiixuWd8EY6aMV pBqQ== MIME-Version: 1.0 X-Received: by 10.140.49.107 with SMTP id p98mr2084606qga.20.1414480986610; Tue, 28 Oct 2014 00:23:06 -0700 (PDT) Received: by 10.140.89.149 with HTTP; Tue, 28 Oct 2014 00:23:06 -0700 (PDT) In-Reply-To: <544F4321.8040302@seld.be> References: <6E04B9BE-854E-4112-8C74-7D90BD8BFE95@ajf.me> <544D48A3.6070905@gmail.com> <572FEBD1-99A8-4788-83F9-D99E470FB16D@ajf.me> <544F4321.8040302@seld.be> Date: Tue, 28 Oct 2014 14:23:06 +0700 Message-ID: To: Jordi Boggiano Cc: PHP internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [RFC] Readonly Properties From: pierre.php@gmail.com (Pierre Joye) On Tue, Oct 28, 2014 at 2:17 PM, Jordi Boggiano wrote: > On 27/10/2014 20:27, Andrea Faulds wrote: >> >> Tentative syntax. But this way, the visibility stays on the left. I thin= k >> that=E2=80=99s good for readability. If you omit the second specifier, t= hen 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. > > > I like it, except for the fact that if you add a custom getter to a prope= rty > suddenly it becomes readonly unless you remember to add "; set" to the en= d > of the block, right? > > How about this instead for readonly: > > public $foobar { > get { return $this->bar * $this->foo; }; readonly > } > > And if the flag isn't there, set is implicitly present. > > That'd mean you also can keep "public readonly $foobar;" as a shorthand f= or > readonly properties without custom getter. I like this idea. Also confirmed what I was trying to say: While we can have many RFCs covering the properties properties and behavior, having one covering the needs in one go will allow us to be more consistent and developer friendly. --=20 Pierre @pierrejoye | http://www.libgd.org