Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61313 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18483 invoked from network); 16 Jul 2012 15:27:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2012 15:27:01 -0000 Authentication-Results: pb1.pair.com header.from=ajfweb@googlemail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajfweb@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: ajfweb@googlemail.com X-Host-Fingerprint: 74.125.82.54 mail-wg0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:33881] helo=mail-wg0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 03/E1-09344-3C234005 for ; Mon, 16 Jul 2012 11:27:00 -0400 Received: by wgx1 with SMTP id 1so1150515wgx.11 for ; Mon, 16 Jul 2012 08:26:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=t/p8zp+XltR9MVA3wnHPlrOvtRvitvWEM0HNJtqn4sI=; b=dIjMPdLQf+TlKamJVeffOHG4vz59iIinZzi57c3e3pZz+3e/wWnbPrYXdIDKq+ny4h aUQ9KJZnBoJtMIaL3VP4yqopLrXTNhpnQJK02bLzB0idvPKHlzgoGEjJ8Xvq/f+6E2qk 2rVNDOGtxs288r7YsvdcUQIukEY2MYJkdqR+0pni7bZAHnOaVcdmVgnWPbvX7b85Sa19 Q2hyeECplv7xIzghVBjCFjdYy3ykrbIEogAELRy/xX+dvoghxgfh8IgyO8mldzET70eO c7av0fiCjE8l16d27rmR1NxuHZKEJSu1pUI3CSYHXeeh5VLuSKkznMJjTKZCUOBbANIi 6w6w== Received: by 10.180.91.228 with SMTP id ch4mr1841806wib.7.1342452416735; Mon, 16 Jul 2012 08:26:56 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.71.199 with HTTP; Mon, 16 Jul 2012 08:26:36 -0700 (PDT) In-Reply-To: References: Date: Mon, 16 Jul 2012 16:26:36 +0100 Message-ID: To: Amaury Bouchard Cc: Nikita Popov , internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] RFC Proposal - Attributes read/write visibility From: ajfweb@googlemail.com (Andrew Faulds) How much syntactic sugar do we really need? Why add two ways to do something? On 16 July 2012 16:24, Amaury Bouchard wrote: > 2012/7/16 Nikita Popov > >> I'm not sure I really understand what this adds over the existing >> getter/setter proposal. read-only and write-only should cover the most >> common cases. If you do need visibility control, it is possible too: >> >> public $property { >> get { ... } >> protected set { ... } >> } >> >> So what does this proposal add to it? >> >> > Yes, but only if you have to write an accessor. > If you just want an attribute that is: > - readable from everywhere > - writable from the current class only > > With my syntax: > public:private $a; (read it aloud "public reading, private writing") > > With the existing RFC: > public $a { > private set { $this->a = $value; } > } > > Which one is better? Why should I write code for that? > > If you read the existing RFC, you'll see that all examples involve a > specific case: when you have a "fake" attribute, which manipulates date > stored in other attributes. The given example is an $Hours attributes, > which is calculated from the private $Seconds attribute. > Again, it could be very useful. But it doesn't work all the time. -- Andrew Faulds (AJF) http://ajf.me/