Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63317 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 1210 invoked from network); 10 Oct 2012 10:42:03 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Oct 2012 10:42:03 -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.219.42 as permitted sender) X-PHP-List-Original-Sender: tbprogrammer@gmail.com X-Host-Fingerprint: 209.85.219.42 mail-oa0-f42.google.com Received: from [209.85.219.42] ([209.85.219.42:35412] helo=mail-oa0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FB/F1-23031-AF055705 for ; Wed, 10 Oct 2012 06:42:03 -0400 Received: by mail-oa0-f42.google.com with SMTP id j1so346544oag.29 for ; Wed, 10 Oct 2012 03:41:59 -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=+SnFjD96KU3ueyRs6ypOfDJlfvRlfEmQM8G6tXQdgMY=; b=a8qvbOiw5GmX5zY5kRzJvPAP/KqRhw8a1u13+3+BpfIMqRW4OfEBiF9na2wmUvvXLf U+P9mqQMQB40tuVRk5pv7ZqdTVG9BFcSXNA3/miJcVmBUCBEKSW4edx96GgZZBKp1NOZ O1qbb1fyThGQpe13Su6NFaYtsXqybUbjzSf78kJbhhIzP6lD/hNDixR8V5c6cz34akce DvO+pRcnc8jyV1VO9WGrxbh16MpoDPzPNPkdopLFGdP6EjnGIRy1Pc1J0hhGAwuP0OmK Ob7qn4S5nvupA1Ik+c8NH4Noh8wMwr7uNoXml/p58qVRnq3xUcEt/ouH1h/E1BYifnO+ zo+A== Received: by 10.182.174.66 with SMTP id bq2mr5285002obc.101.1349865719851; Wed, 10 Oct 2012 03:41:59 -0700 (PDT) MIME-Version: 1.0 Received: by 10.76.11.170 with HTTP; Wed, 10 Oct 2012 03:41:38 -0700 (PDT) In-Reply-To: References: <9570D903A3BECE4092E924C2985CE485612B3B48@MBX202.domain.local> <9570D903A3BECE4092E924C2985CE485612B496D@MBX202.domain.local> Date: Wed, 10 Oct 2012 03:41:38 -0700 Message-ID: To: Leigh Cc: Bernhard Schussek , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=e89a8f5024eeb9ec4304cbb21af3 Subject: Re: [PHP-DEV] [RFC] Propety Accessors v1.1 From: tbprogrammer@gmail.com (Jazzer Dane) --e89a8f5024eeb9ec4304cbb21af3 Content-Type: text/plain; charset=ISO-8859-1 Here's my feedback on some current outstanding issues/suggestions: 1) Default value: I think having functionality for a default value is necessary, but I'm also thinking it may already be implementable within the current syntax. > class Test { > private $seconds; > public $hours { > get() { > if(!is_null($this->seconds)) { > return $this->seconds; > } else { > return 10; // 10 is default > } > } > } > } > The above should work fine in many scenarios, right? We could perhaps then claim that the issue may rather be that we need access to the variable *$hours* itself inside of the get/set/etc functions, which I think has been brought up before - though I'm not so sure how sensible that is. Whether we need that or not is up in the air. 2) read-only and write-only is ugly. While this is a bias, I think we can do better. One idea I had is exactly what bernhard suggesting - using *final private set() {}* to achieve read-only functionality. My problem with this implementation is that it's not as logical as I'd prefer. In my eyes, from a logical point of view, just the fact that set is there means that it works. Thus it just so happens that, while setting the variable doesn't error out, it does absolutely nothing. While I don't see any real world scenarios where people would want this behavior, I still am wrestling with this proposed implementation, as I think that, logically speaking, set should work but just not do anything. Whether or not this is illogical is arguably none of our concern - it's the coder's concern. Hmm. I'd definitely like to explore other alternatives to this solution. Already proposed: > public read-only $property { > get() { ... } > } > public $property { > get() { ... } > final private set() {}; > } > I'm going to throw out some alternatives just for the sake of it. They may be more illogical than I'd prefer, but I'm just trying to get the juices flowing: > public $property { > get() { ... } > final private set; > } > public $property { > get() { ... } > final private set(); > } > public $property { > get_only() { ... } // Same as get but implies read only; set not > allowed to be defined. In case of set_only and get_only, top one has > precedence. > } > public $property { > set(read_only); > get() { ... } > } > public $property { > read_only; // or read_only(); > get() { ... } > } > 3) I'll agree with Leigh here: > I don't like the fact that accessors and their associated properties are > implemented as direct (yet slightly obfuscated/hidden) elements of the > containing class. It's unintuitive (I'd even go as far as saying confusing). > 4) In regards to array accessors, it'd be nice to have but not at all necessary. On Wed, Oct 10, 2012 at 2:29 AM, Leigh wrote: > On 10 October 2012 08:46, Bernhard Schussek wrote: > > > Second, I'd like to throw in the idea of array accessors. I mentioned > > this before, but did not get any response. > > > > public $Addresses { > > offsetSet($offset, $value) { ... } > > offsetGet() { ... } > > offsetUnset($offset) { ... } > > offsetExists($offset) { ... } > > } > > Definitely on the "nice to have" list. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --e89a8f5024eeb9ec4304cbb21af3--