Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60277 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96227 invoked from network); 24 Apr 2012 12:59:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Apr 2012 12:59:22 -0000 Authentication-Results: pb1.pair.com header.from=kontakt@beberlei.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=kontakt@beberlei.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain beberlei.de from 209.85.215.42 cause and error) X-PHP-List-Original-Sender: kontakt@beberlei.de X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:46778] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/4B-34190-7A3A69F4 for ; Tue, 24 Apr 2012 08:59:21 -0400 Received: by lahl5 with SMTP id l5so457883lah.29 for ; Tue, 24 Apr 2012 05:59:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:content-type:x-gm-message-state; bh=dKtlzu+RpmpRY8OK3FohMBA1jxF/BTRFhO35u24p6+M=; b=ST7NoPawEg+jUaJR/3X610LCEo4Ce4f6O4s2vmpwd/FbFzkTLi/TlGUs4OjJpqUP+l W1u7CaubkIZaEfS776sCBMbluWReQ7Jq8h2BlJcC0A87Ci43drHpn/xMHOJ6cA1ZSaFI ozgYvF/A94o2/hbAkk5YBw/1GMl5asmwNZWNRNda4CO1HBnGIget3sVMJqikSAklvGty TFuYmKEWqqkG2zwjN4I2d5ktWrZKS97oCsrH7ZdDD2vNwKuqvGKNpCsp8eGBkDKuJu80 4Su6DKktGSb0KTweaCCfDb+XWksv/swIon809KYC6Bs/C/gTCc33Cm1ShMKQi4jGIjAa VYvg== MIME-Version: 1.0 Received: by 10.152.106.9 with SMTP id gq9mr3458421lab.14.1335272357230; Tue, 24 Apr 2012 05:59:17 -0700 (PDT) Received: by 10.112.39.132 with HTTP; Tue, 24 Apr 2012 05:59:17 -0700 (PDT) X-Originating-IP: [178.200.247.30] In-Reply-To: References: <9570D903A3BECE4092E924C2985CE48555BEC3C2@MBX202.domain.local> Date: Tue, 24 Apr 2012 14:59:17 +0200 Message-ID: To: Anthony Ferrara Cc: Clint M Priest , "internals@lists.php.net" Content-Type: multipart/alternative; boundary=f46d0408d3bf87f97604be6c525e X-Gm-Message-State: ALoCoQmvFthd+1UNn40eXo7zfiDXrkWGEkVJ8I+IqbI7l1MGEGj4WFcZE9/sPf8fkj4texqzAh7y Subject: Re: [PHP-DEV] RFC: Property get/set syntax (added isset/unset and references) From: kontakt@beberlei.de (Benjamin Eberlei) --f46d0408d3bf87f97604be6c525e Content-Type: text/plain; charset=ISO-8859-1 Hi! would it be possible to add a second shorthand syntax to the complete automatic implementation? Examples: class TimePeriod { public $Hours {}; public property $Hours; public $Hours {property}; } That could save quite some typing. Overall, i really like it. On Tue, Apr 24, 2012 at 2:56 PM, Anthony Ferrara wrote: > Clint, > > Very nice job overall! Looking quite good. > > > Alternatively we could throw an error to a call on isset and/or unset > against a property which didn't define an implementation. > > I don't care for that concept much. All it's doing is trading one set > of boilerplate for another. I'd prefer the get() !== null approach, > since there is a zval allocated for it, so the isset() part. > > And I do like the unset overloading, which is right inline with > __unset()... > > Additionally, is something like this possible? > > class Foo { > private $bar = 1; > public $bar { > get { return $this->bar; } > set { $this->bar = (int) $value; } > } > } > > The reason that I ask, is that's kind of what's done with __get() and > __set() right now, the magic is called when it's out of scope. So in > this case, we can have a public variable with the same name as the > private one, but with validations attached to the public exposure... > > Just a thought... > > Anthony > > On Tue, Apr 24, 2012 at 8:31 AM, Clint M Priest > wrote: > > I've updated the RFC to include details on adding isset/unset as well as > references, detailed below: > > > > isset/unset: > > > > class TimePeriod { > > private $Seconds = 3600; > > > > public $Hours { > > get { return $this->Seconds / 3600; } > > set { $this->Seconds = $value; } > > isset { return !is_null($this->Seconds); } > > unset { $this->Seconds = NULL; } > > } > > } > > > > References: > > > > > > class SampleClass { > > > > private $_dataArray = array(1,2,5,3); > > > > > > > > public $dataArray { > > > > &get { return &$this->_dataArray; } > > > > } > > > > } > > > > > > > > $o = new SampleClass(); > > > > sort($o->dataArray); > > > > /* $o->dataArray == array(1,2,3,5); */ > > > > Comments? > > > > These would also include automatic implementations which call the > respective functions on the backing field. I could see only allowing > isset/unset automatic implementations if get/set were also specified as > automatic implementations. > > > > Default implementations of isset/unset > > > > I'm also fielding comments/ideas on a way to always provide automatic > implementations of isset/unset for any accessor that didn't define one > automatically. One idea was for the isset (unspecified implementation) > which would return true if the getter provided any value which evaluated to > true, such as this: > > > > class TimePeriod { > > private $Seconds = 3600; > > > > public $Hours { > > get { return $this->Seconds / 3600; } > > set { $this->Seconds = $value; } > > } > > } > > /* Default Implementation Concept */ > > > > isset { return (int)$this->Hours; } > > unset { $this->Hours = NULL; } > > > > Note that the automatic implementation of unset is not strictly the same > as an unset() but without any sort of unset implementation a call to > unset() would do nothing. Alternatively we could throw an error to a call > on isset and/or unset against a property which didn't define an > implementation. > > > > Thoughts? > > > > -Clint > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --f46d0408d3bf87f97604be6c525e--