Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:56787 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26192 invoked from network); 6 Dec 2011 03:23:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Dec 2011 03:23:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=cpriest@zerocue.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cpriest@zerocue.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zerocue.com designates 74.115.204.51 as permitted sender) X-PHP-List-Original-Sender: cpriest@zerocue.com X-Host-Fingerprint: 74.115.204.51 relay-hub201.domainlocalhost.com Received: from [74.115.204.51] ([74.115.204.51:11830] helo=relay-hub201.domainlocalhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A1/50-23324-BCA8DDE4 for ; Mon, 05 Dec 2011 22:23:57 -0500 Received: from MBX202.domain.local ([169.254.2.249]) by HUB201.domain.local ([74.115.204.51]) with mapi id 14.01.0289.001; Mon, 5 Dec 2011 22:23:53 -0500 To: Rasmus Schultz , "internals@lists.php.net" Thread-Topic: [PHP-DEV] Re: Patch: getters/setters syntax Implementation Thread-Index: AQHMs6YR/e0RMhrEek+dmbZ3mDNhgZXOJKmA Date: Tue, 6 Dec 2011 03:23:52 +0000 Message-ID: <9570D903A3BECE4092E924C2985CE4853994C39F@MBX202.domain.local> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [192.168.64.22] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: [PHP-DEV] Re: Patch: getters/setters syntax Implementation From: cpriest@zerocue.com (Clint M Priest) I believe the attempt with the RFC was to mimic the syntax that C# went wit= h, the RFC is here: https://wiki.php.net/rfc/propertygetsetsyntax The first public would apply to either of the get/set which did not have it= further defined, for example: public $Hours { get { ... } private set { ... } } Also, with automatic implementations (at present) the parent access level c= ontrols the automatic property generation: private $Hours { public get; public set; } Would define an internal variable of $__Hours as private. Perhaps it shoul= d always be a private internal variable, it was not designated in the rfc a= nd I made it this way to be the most flexible for the author. -----Original Message----- From: Rasmus Schultz [mailto:rasmus@mindplay.dk]=20 Sent: Monday, December 05, 2011 5:11 PM To: internals@lists.php.net Subject: [PHP-DEV] Re: Patch: getters/setters syntax Implementation 2011/12/4 Clint M Priest : > Updated patch w/o white-space: http://www.clintpriest.com/patches/accessors_v1.patch > > In the end it is a relatively simple patch. The new syntax=20 > effectively creates internal functions on the object and the system looks for those fun= ctions and calls them at the appropriate time. > > Example: > class z { > public $Hours { > public get { return $this->_Hours; } > protected set { $this->_Hours =3D $value; } > } > } > > Defines: > $o->__getHours(); > $o->__setHours($value); You forgot to declare the backing field z::$_Hours in this example. From a semantic point of view, I find it misleading to first declare $Hours= as public, then lowering the bar by making the set-accessor protected. The most common use-case for accessors is public - so I would suggest a syn= tax more along the lines of this: class z { private $_hours; get $hours { // accessor is public by default return $this->_hours; } protected set $hours { $this->_hours =3D $hours; // local variable $hours is the new value } } And perhaps a short form for added convenience, where the backing-field is = automatically added for you - e.g.: class z { get $hours { // accessor is public by default return $value; // $value provides access to the backing field (same way= $this provides access to the object context) } protected set $hours { $value =3D $hours; // local variable $hours is the new value, $value re= ferences the backing field } } thoughts?