Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63329 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83259 invoked from network); 11 Oct 2012 00:07:04 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Oct 2012 00:07:04 -0000 Authentication-Results: pb1.pair.com header.from=cpriest@zerocue.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cpriest@zerocue.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zerocue.com designates 74.115.204.80 as permitted sender) X-PHP-List-Original-Sender: cpriest@zerocue.com X-Host-Fingerprint: 74.115.204.80 relay-hub206.domainlocalhost.com Received: from [74.115.204.80] ([74.115.204.80:59507] helo=relay-hub206.domainlocalhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 83/61-23031-4AD06705 for ; Wed, 10 Oct 2012 20:07:04 -0400 Received: from MBX202.domain.local ([169.254.169.44]) by HUB206.domain.local ([192.168.68.50]) with mapi id 14.02.0283.003; Wed, 10 Oct 2012 20:06:12 -0400 To: Rasmus Schultz , "internals@lists.php.net" Thread-Topic: [PHP-DEV] [RFC] Propety Accessors v1.1 Thread-Index: AQHNp0F80wLAVcGGQAyyWuaNO91x4ZezOa5w Date: Thu, 11 Oct 2012 00:06:16 +0000 Message-ID: <9570D903A3BECE4092E924C2985CE485612B4E9F@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.21] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: [PHP-DEV] [RFC] Propety Accessors v1.1 From: cpriest@zerocue.com (Clint Priest) Jazzer's example was extending an accessor and her statement about no way t= o stop the developer from doing what she did there without read-only is cor= rect. There are other, more verbose and less simple ways to accomplish read-only = and write-only (preventing sub-classes from defining a getter, etc, namely = through the use of final) but none of them are as simple and easily readabl= e as public read-only $hours { ... } > -----Original Message----- > From: Rasmus Schultz [mailto:rasmus@mindplay.dk] > Sent: Wednesday, October 10, 2012 6:47 PM > To: internals@lists.php.net > Subject: Re: [PHP-DEV] [RFC] Propety Accessors v1.1 >=20 > > There's no way to stop the developer from doing that without read-only. >=20 > Yes, there is - I don't even know why would write it that way - doesn't s= eem to make much sense. >=20 > What you probably should be doing, is this: >=20 > class A { > private $seconds =3D 3600; >=20 > public $hours { > get() { return $this->seconds / 3600 }; > } > } >=20 > Keep your field private - now try extending this with a write-accessor. >=20 > I think that read-only is really almost merely a "pseudonym" for "read-on= ly accessor for a private field" - what you're really trying to > do, is protect the field behind the accessor, not the accessor itself. >=20 > In the same way, write-only is practically synonymous with "write-only ac= cessor for a private field" - to some extend (at least) the > point of having accessors to begin with, is to protect the underlying val= ue(s) from unauthorized or incorrect use. >=20 > You can relax your read-only or write-only accessors by declaring the bac= king field(s) protected - this would be the equivalent of > declaring a read-only accessor that you are permitted to extend with a wr= ite-accessor if you need to... >=20 >=20 > ---------- Forwarded message ---------- > From: Jazzer Dane > To: Leigh > Cc: Clint Priest , "internals@lists.php.net" < inter= nals@lists.php.net> > Date: Tue, 9 Oct 2012 19:33:20 -0700 > Subject: Re: [PHP-DEV] [RFC] Propety Accessors v1.1 >=20 > > class A { > > > public $seconds =3D 3600; > > > > > > public $hours { > > > get() { return $this->seconds / 3600 }; > > > } > > > } > > > > > > class B extends A { > > > public $hours { // Maintains 'get' from class A > > > set($value) { $this->seconds =3D $value; } > > > } > > > } > > > > > ^There's no way to stop the developer from doing that without read-only= .