Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61319 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28005 invoked from network); 16 Jul 2012 15:42:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2012 15:42:15 -0000 Authentication-Results: pb1.pair.com smtp.mail=amaury.bouchard@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=amaury.bouchard@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: amaury.bouchard@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:47707] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 35/04-09344-65634005 for ; Mon, 16 Jul 2012 11:42:14 -0400 Received: by obfk16 with SMTP id k16so11403129obf.29 for ; Mon, 16 Jul 2012 08:42:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=/rcswE4l5jndrHNtL4t9EEsmBZAFx+ovXa8K2LmQw94=; b=n6oWY9ZB3FHrtSjaNT4VJLSePGesr+tNGTfWL/t7lHARfRc8L40Lj4q1+WuEUDzdRB ybkZLgZ/gU/sW/HMj/PVNepOKpkV9E/ShtnRauouWQoMVjWoie0y3Z9EytkJDkuRCZVu C5mFnSfzIbKZEoZUl5KCxz/hQD8gbxek2sENCW2XmqaywIOoc06qhuroy94YGGlO/hmP 5yqxzHQ/cenvIkDyRJOkIgB9HYEnU1s0f8R/CQpFMz3kJm13fynkvopimtv4m36q6U76 /70HmsLgWdwwZ9ynp27CX47ZIEhWnj46Ln1Q0KEeDpfeMucaTO3XJfGqOAa9asAgNkQs X+YQ== Received: by 10.182.164.40 with SMTP id yn8mr8334580obb.40.1342453331557; Mon, 16 Jul 2012 08:42:11 -0700 (PDT) MIME-Version: 1.0 Sender: amaury.bouchard@gmail.com Received: by 10.182.60.131 with HTTP; Mon, 16 Jul 2012 08:41:50 -0700 (PDT) In-Reply-To: References: Date: Mon, 16 Jul 2012 17:41:50 +0200 X-Google-Sender-Auth: hyXPF2mM8_hpS52uXmhjJkVFiyw Message-ID: To: Nikita Popov Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=e89a8f642feef47b2704c4f445b0 Subject: Re: [PHP-DEV] RFC Proposal - Attributes read/write visibility From: amaury@amaury.net (Amaury Bouchard) --e89a8f642feef47b2704c4f445b0 Content-Type: text/plain; charset=ISO-8859-1 Are you sure that this mix of distributed visibilities (sometimes before the attribute, sometimes before a "get" or "set" keyword) and new keywords ("read-only" and "write-only", between the initial visibility and the attribute itself; but what is an "initial visibility" exactly?) is really more clear? Take this code, for instance: public read-only $a { protected get; private set; } Yeah, I know, the "public" should be "protected". But in some years, when you'll have some legacy code, I'm pretty sure we will see this kind of code. It should work, the "public" visibility is just overloaded by the "protected" and "private" visibilities. Anyway, it's perturbing. Oh, and there is a "read-only" keyword. Damned, I added a private setter, I forgot it was read-only and I forgot to remove it... So, I guess it should be like that: protected $a { private set; } Then, try to read this code aloud. I'm really not sure it's better than a simple "protected:private $a;", which could be read like "protected reading, private writing". 2012/7/16 Nikita Popov > On Mon, Jul 16, 2012 at 5:24 PM, Amaury Bouchard > wrote: > > 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. > > You can also just write public $a { get; private set; }. I see that > the syntax is a bit more verbose, but I definitely prefer it to the > obscure public:private notation. With the getters/setters the meaning > is somewhat clear (public get, private set), with the colon notation > it isn't really clear. > > Nikita > --e89a8f642feef47b2704c4f445b0--