Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63328 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81186 invoked from network); 10 Oct 2012 23:46:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Oct 2012 23:46:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.212.42 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.212.42 mail-vb0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:44373] helo=mail-vb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/F0-23031-FD806705 for ; Wed, 10 Oct 2012 19:46:40 -0400 Received: by mail-vb0-f42.google.com with SMTP id fs19so1194554vbb.29 for ; Wed, 10 Oct 2012 16:46:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type :x-gm-message-state; bh=9xBi93sdAGFINNtstI3um2q/cHw5A4Rdosp4gu2prGk=; b=fcYcFN9Kdba6ZazI0JNV9qCDG+xP2r9wIPxZc5ylsJQ9q84xFc3S3L58xQ9FTnloc7 BqSL2LGNMbpmKUCDDizU0Yn6aQIYoAGFyZHyzvPAYJbqbYDNTLc0XNV12Zx/07gdZtrU B1F/SYdFu2+TMq5fYt+hUNkkDtAR8HH8dn5gcaxkOV3hzEuUp5LKP9wmyiG7z5S7g5Wk /8TLzTwx3vjTGQYW7AvWXo9DhCoeY58hoRaTRdiAbAGTiWMWNSpi2Z4KL1Yd0Z9x4dXI E0qqghfham8xvU1xL1EZaPeM2SaP3P/eqtbO7XaJRah9K1AVdB3iAyLRxbKviowJx76u 48nQ== MIME-Version: 1.0 Received: by 10.220.240.135 with SMTP id la7mr6815447vcb.44.1349912796129; Wed, 10 Oct 2012 16:46:36 -0700 (PDT) Received: by 10.58.146.103 with HTTP; Wed, 10 Oct 2012 16:46:36 -0700 (PDT) Date: Wed, 10 Oct 2012 19:46:36 -0400 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=14dae9cfc73ab0e8a304cbbd106f X-Gm-Message-State: ALoCoQmvt6yYnVXis/QI+ytyIVn6jbh/YBfuqi4zame5mvM/XmQOxOb9+uOZ7+DP9zfnICtoTPw+ Subject: Re: [PHP-DEV] [RFC] Propety Accessors v1.1 From: rasmus@mindplay.dk (Rasmus Schultz) --14dae9cfc73ab0e8a304cbbd106f Content-Type: text/plain; charset=ISO-8859-1 > There's no way to stop the developer from doing that without read-only. Yes, there is - I don't even know why would write it that way - doesn't seem to make much sense. What you probably should be doing, is this: class A { private $seconds = 3600; public $hours { get() { return $this->seconds / 3600 }; } } Keep your field private - now try extending this with a write-accessor. I think that read-only is really almost merely a "pseudonym" for "read-only accessor for a private field" - what you're really trying to do, is protect the field behind the accessor, not the accessor itself. In the same way, write-only is practically synonymous with "write-only accessor for a private field" - to some extend (at least) the point of having accessors to begin with, is to protect the underlying value(s) from unauthorized or incorrect use. You can relax your read-only or write-only accessors by declaring the backing field(s) protected - this would be the equivalent of declaring a read-only accessor that you are permitted to extend with a write-accessor if you need to... ---------- Forwarded message ---------- From: Jazzer Dane To: Leigh Cc: Clint Priest , "internals@lists.php.net" < internals@lists.php.net> Date: Tue, 9 Oct 2012 19:33:20 -0700 Subject: Re: [PHP-DEV] [RFC] Propety Accessors v1.1 > class A { > > public $seconds = 3600; > > > > public $hours { > > get() { return $this->seconds / 3600 }; > > } > > } > > > > class B extends A { > > public $hours { // Maintains 'get' from class A > > set($value) { $this->seconds = $value; } > > } > > } > > > ^There's no way to stop the developer from doing that without read-only. --14dae9cfc73ab0e8a304cbbd106f--