Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61314 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20028 invoked from network); 16 Jul 2012 15:30:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Jul 2012 15:30:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:40706] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F4/42-09344-87334005 for ; Mon, 16 Jul 2012 11:30:01 -0400 Received: by lbgc1 with SMTP id c1so8585293lbg.29 for ; Mon, 16 Jul 2012 08:29:57 -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; bh=nwhc+byLuQLKTKzeRD+tkrhLZHPwg1JzhKyNcTCSufQ=; b=DJU1iIVLnePkzGRUV9fZHGJCpRtYUW/9egDdQWm+XNkngap3LHyTYzr3G/fJe3QXMw Gd1qsbjZ8ZlYPukMp50kQrvGpyjE3EG+b60voEs87bdOJARXdwtPCFx0uMCZGjwW3mWv 3Ce9LSeXOvCiKQVXD4OJv1xKSAecdp/6TxEOHtjcsL4jB2v3IYdLTs7LespLxhZC+mw+ tay8meG+qCF0uPDkfJNk3IEtbrUJ/4QUwv5OW0NJ8U8YydcMiXHYmKl+pKWK1Ph1jam2 4EiHcTSokhNzhDdOYr81+HqcXmRm01UCDZhy7xpP5mcjfuHE9NDxbxPAJkKKK2KkAZgY YTtw== MIME-Version: 1.0 Received: by 10.112.54.100 with SMTP id i4mr5457156lbp.97.1342452597614; Mon, 16 Jul 2012 08:29:57 -0700 (PDT) Received: by 10.152.114.70 with HTTP; Mon, 16 Jul 2012 08:29:57 -0700 (PDT) In-Reply-To: References: Date: Mon, 16 Jul 2012 17:29:57 +0200 Message-ID: To: Amaury Bouchard Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] RFC Proposal - Attributes read/write visibility From: nikita.ppv@gmail.com (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