Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61248 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 70072 invoked from network); 15 Jul 2012 15:50:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jul 2012 15:50:36 -0000 Authentication-Results: pb1.pair.com header.from=brandon.wamboldt@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=brandon.wamboldt@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: brandon.wamboldt@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-bk0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:41417] helo=mail-bk0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1C/3C-20866-AC6E2005 for ; Sun, 15 Jul 2012 11:50:34 -0400 Received: by bkcjm19 with SMTP id jm19so3788180bkc.29 for ; Sun, 15 Jul 2012 08:50:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=U1+JTfQ+PghKYVJmBRwD7sEXU0itjMbo6ZBl4psEcqc=; b=QR+1wBIxQ36VqxhFcCqKUrtwKQRd7Kz1CM0uiqoEFJW65wWq7GVKJnyxWw918GwWcL OclswuuTjkyvVFGUa9+dyA7IHGYO3YX9ivuLpCfs8fOIQwXHb1Fvp2ibo5iSnTPFPpnU qrRlCCs8EqcZ8ynBdy8mwwNacRggmXyYtNdExBlzfuzdxk6iZUuBaR5/HXl21+bD+x5N OsPS52Jx1WJsJt8XV7lO2A1gJTbHA22e5M404cWvaB4OyFHM/pYloUZwx3XidYiPISZp /FcBuwyJ+9b+VZzFIPDNNyf/kORga38aHr9zLdqv2bhK3q754pUVZIr3+maoWK3xR0mA 2m8Q== Received: by 10.204.154.73 with SMTP id n9mr3561905bkw.113.1342367431119; Sun, 15 Jul 2012 08:50:31 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.140.139 with HTTP; Sun, 15 Jul 2012 08:50:11 -0700 (PDT) In-Reply-To: References: Date: Sun, 15 Jul 2012 12:50:11 -0300 Message-ID: To: Amaury Bouchard Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=0015175cd184e3d46b04c4e045f3 Subject: Re: [PHP-DEV] RFC Proposal - Attributes read/write visibility From: brandon.wamboldt@gmail.com (Brandon Wamboldt) --0015175cd184e3d46b04c4e045f3 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable This seems pretty useful, but could technically be accomplished using the get/set syntax already proposed. Obviously this is a cleaner implementation however. On Sun, Jul 15, 2012 at 12:46 PM, Amaury Bouchard wrote= : > Hi, > > Here is an RFC proposal about a syntax extension for PHP. The purpose is = to > manage precisely the visbiliy of attributes, by separating reading and > writing access. > > First of all, I know there is already an RFC about attributes ("Property > get/set syntax" [1]). Its goal is mainly different, but I'll discuss it > lower. > > > THE PROBLEM > In my experience, one of the major usage of getters is when you want to > have an attribute, readable (but not writable) from outside the object. > More, the attribute's visibilty is then chosen between private and > protected, depending on your inheritance design. > > The result is not really satisfying: > 1. You have to write getter's code. Maybe, it's just a simple return, but > every line of code should be useful, not a workaround. > 2. You ended with 2 syntaxes; $obj->attr when the attribute is public, bu= t > $obj->getAttr() when you must use a getter. It's a bit schizophrenic. > > > THE IDEA > I suggest to be able to separate reading visibility and writing visibilit= y, > using a colon to separate them. If only one visibility is given, it will = be > used for both reading and writing access. > > For example: > class A { > public $a; // public reading, public writing > public:public $b; // the same > public:protected $c; // public reading, protected writing > public:private $d; // public reading, private writing > public:const $e; // public reading, no writing allowed > > protected $f; // protected reading, protected writing > protected:protected $g; // the same > protected:private $h; // protected reading, private writing > protected:const $i; // protected reading, no writing allowed > > private $j; // private reading, private writing > private:private $k; // the same > private:const $l; // private reading, no writing allowed > } > > As you can see, I think that writing access should be more restrictive th= an > reading access (or equivalent to it). A "private:public" visibility would > make no sense. > > > SOURCE CODE > I did a patch. It kinda works, but I'm still working on it (because I'm > still learning Zend Engine's internals). > The code on GitHub: https://github.com/Amaury/php-src > All advises are welcome. > > > PRIOR WORK > As I said before, the "Property get/set syntax" RFC is in discussion. My > proposal doesn't focus on the same goals, but they could be fully > compatible. > > Thus, we would be able to write this kind of code: > class A { > // $str has public reading and private writing, > // and manage french quotes > public:private $str { > get { return "=AB" . $this->str . "=BB"; } > set { $this->str =3D trim($value, "=AB=BB"); } > } > } > > Maybe you saw that the "Property get/set syntax" RFC has an intended synt= ax > for read-only and write-only attributes. From my point of view, there is = a > deep and clean separation between a getter/setter syntax and an extended > visibility syntax. It shouldn't be in the same RFC. > More, the proposed "read-only" and "write-only" keywords are less precise > and powerful than what I'm suggesting. > > > I would be happy to discuss all that with you guys. > > Best regards, > > Amaury Bouchard > > > [1] : https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented > --=20 *Brandon Wamboldt* Programmer / Web Developer StackOverflow Careers Profile- GitHub Profile - LinkedIn - My Blog --0015175cd184e3d46b04c4e045f3--