Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78415 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26552 invoked from network); 28 Oct 2014 07:17:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Oct 2014 07:17:58 -0000 Authentication-Results: pb1.pair.com header.from=j.boggiano@seld.be; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=j.boggiano@seld.be; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain seld.be designates 209.85.212.177 as permitted sender) X-PHP-List-Original-Sender: j.boggiano@seld.be X-Host-Fingerprint: 209.85.212.177 mail-wi0-f177.google.com Received: from [209.85.212.177] ([209.85.212.177:52189] helo=mail-wi0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 64/80-21571-4234F445 for ; Tue, 28 Oct 2014 02:17:58 -0500 Received: by mail-wi0-f177.google.com with SMTP id ex7so620324wid.4 for ; Tue, 28 Oct 2014 00:17:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=vyRvTWhL2uvUVEkQ1AxvJ9uxz/nZpZzNKBIKvzawERI=; b=gORn+UzVBxQyNznDMcTYSpxmaxad+7SfTZ3hYO+wSizxzTNWnNaBHh9Q1dx5kWtfLe vP5EEHxNCj7w2pUtZcKB89zjZsys/TUMPUTIYXMN4tck1BZunD0/x7lSJ6UEZWdg71Mu U3StGCiTfAz+GmK8SMQ6QVbC8IrgD1lbpI6taxWjKSXBpqLJ6jUqv2yFMuBUhHdkrJC5 sXvBns+7BYxRD3d2kzxB6SW3hH/EA09TPgvy9ZISzSfeQkk5PxU1rApJSxYcSYWqpAYl u8LnyZbdJZNSmTSsCoBFyJ3jKeaebc9L8jMynK017e/7Y4tHwmLK/MpNKb6R3gXxvhXc +1ZQ== X-Gm-Message-State: ALoCoQlxXW264l1TRnT09Yg7w7w/scUJgpJBojOebid22kf/8mM2T0bxjUSVnZ4XWiUpBv/ZMq6s X-Received: by 10.180.20.162 with SMTP id o2mr2389317wie.57.1414480674385; Tue, 28 Oct 2014 00:17:54 -0700 (PDT) Received: from [172.20.2.201] ([67.50.1.50]) by mx.google.com with ESMTPSA id gw6sm1135128wib.8.2014.10.28.00.17.52 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 28 Oct 2014 00:17:53 -0700 (PDT) Message-ID: <544F4321.8040302@seld.be> Date: Tue, 28 Oct 2014 07:17:53 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: internals@lists.php.net References: <6E04B9BE-854E-4112-8C74-7D90BD8BFE95@ajf.me> <544D48A3.6070905@gmail.com> <572FEBD1-99A8-4788-83F9-D99E470FB16D@ajf.me> In-Reply-To: <572FEBD1-99A8-4788-83F9-D99E470FB16D@ajf.me> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Readonly Properties From: j.boggiano@seld.be (Jordi Boggiano) On 27/10/2014 20:27, Andrea Faulds wrote: > Tentative syntax. But this way, the visibility stays on the left. I think that’s 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’d also be compatible with properties, too: > > public/private $foobar { > get { return $this->bar * $this->foo; } > set($value) { $this->bar = $value / $this->foo; } > } > > It doesn’t 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 property suddenly it becomes readonly unless you remember to add "; set" to the end 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 for readonly properties without custom getter. Cheers -- Jordi Boggiano @seldaek - http://nelm.io/jordi