Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63310 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64170 invoked from network); 10 Oct 2012 02:33:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Oct 2012 02:33:44 -0000 Authentication-Results: pb1.pair.com header.from=tbprogrammer@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tbprogrammer@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: tbprogrammer@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:35802] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 20/40-62296-78ED4705 for ; Tue, 09 Oct 2012 22:33:44 -0400 Received: by mail-ob0-f170.google.com with SMTP id ni5so37933obc.29 for ; Tue, 09 Oct 2012 19:33:41 -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=825XpKEBSh7DXw2tGrnWtczItojDVx45wXV/vqzoAeM=; b=WgD57ibSWtMX/CcmzSf/Xjq7DexfWa7BRqYaAWczDxM2JmWq9pTGYqRbcNtqrvYmQ8 L5daoNCSnRfxvFkglrnHMH2cwoj6tYqVCfou4qvdGSxi61FpDE4wn2XsHQr9y3x4YGAr y1OE2PJ53MLfj+ZzxqyWjm+fAzlzDRPjpTcX4mkcqIMrXOZgxCQ7nDtk98TIkOyK458n HM/zZGA3gj/c4zK55CcasfYr79G08l0uKD3vgbP3eLDjTnZTZccp+Rr8fkR9JYTzTV85 t5b9cbzs51257ddNQP3xUKzEKBTDYqmu9RuHfT9VR3QTnx79yoN787PAa4ZeOvySZrfx MrXA== Received: by 10.60.19.37 with SMTP id b5mr18260455oee.16.1349836421099; Tue, 09 Oct 2012 19:33:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.11.170 with HTTP; Tue, 9 Oct 2012 19:33:20 -0700 (PDT) In-Reply-To: References: <9570D903A3BECE4092E924C2985CE485612B3B48@MBX202.domain.local> Date: Tue, 9 Oct 2012 19:33:20 -0700 Message-ID: To: Leigh Cc: Clint Priest , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=e89a8ff1c4b86271d804cbab48d3 Subject: Re: [PHP-DEV] [RFC] Propety Accessors v1.1 From: tbprogrammer@gmail.com (Jazzer Dane) --e89a8ff1c4b86271d804cbab48d3 Content-Type: text/plain; charset=ISO-8859-1 I think Leigh brings up some important flaws to in the current RFC. What Leigh is asking for does not appear to be possible, and in my opinion, it should be. I also agree with Rasmus, to a certain extent. By putting only a getter/setter, the developer essentially sets the property as read or write only. At first glance, there is no need for the read-only or write-only keyword. Except... subclassing may or may not be an issue. By setting a property to read-only, it ensures that 'set' can never be set by a subclass. Unless I redefine the entire property... or is that not even possible? *The RFC isn't very clear but it appears that there is no way to redefine the entire property, as if you define it in the subclass with only get, then it will take set, isset, and unset from the parent class, correct? * Though, that can be outright stopped by making the property final. But then there is no point in having read/write-only. From what I can tell, read-only becomes useful if I extend the class and want to partially modify the property. Example: > 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. Also, if the property is public, what if an outside class tries to do this: > class A { > public $seconds = 3600; > > public $hours { > get() { return $this->seconds / 3600 }; > } > } > > $object = new A(); > $object->hours = 100; > What happens then? And similarly, how do we set a public property as a property accessor, hmm? class A { > public $hours = 1; > } > > $seconds = 20; > > $object = new A(); > $object->hours = { // Does this work? > get() { return $seconds; } > }; > There's definitely still some questions to answer before this RFC is ready. On Tue, Oct 9, 2012 at 10:19 AM, Leigh wrote: > > RFC Document: > https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented > > public $property { > set { $this->property = ($this->property*2)+$value } > get; > } > > How do I reference the property being set from within the function? The way > I have done it in the example will cause recursion? How can I assign to > "self"? > > How do I set the default value of $property when the object is created? > Surely I don't have to reverse the set accessors logic and set the inverse > in __construct? > --e89a8ff1c4b86271d804cbab48d3--