Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60276 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94941 invoked from network); 24 Apr 2012 12:56:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Apr 2012 12:56:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=ircmaxell@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ircmaxell@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: ircmaxell@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-wg0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:35648] helo=mail-wg0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/FA-34190-913A69F4 for ; Tue, 24 Apr 2012 08:56:58 -0400 Received: by wgbfg15 with SMTP id fg15so485287wgb.11 for ; Tue, 24 Apr 2012 05:56:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=Rnd3mvUPB4Sp+o8qOtH5r9ZErP4SFkAx6k01OSe2qjI=; b=DQmzPlSqSdQqa9QVDHJkgsv2JKzmnuvVg2VZfbVoxs8lII1fvp7Dv/j9Y5urv/N6Hh 8WF+MUhjbH78VD4cetypm19lL83OiIaN0zi9NLZl3X0UiJGznCVP+BuwZFx+4QOIvtXH R2wu7vowTbrOzU/9NsMh4IQvwLxds0OPZ404XHPQcwqPBv1pehrC+2CuGjuhi1nmy5RJ HwzflD6BZm+CGB5f6+QrhpY3FDHhnQUDoRjj2SJE/byzUk7Qb0fqZOzoekQjgLjQDLT5 +AfJreebnG6vKrrJYuIsS92uF/KcfXM4x3NgcWKmgk02kfGrXQIA/33RVwl7+LfWjCaJ r7Ig== MIME-Version: 1.0 Received: by 10.216.134.19 with SMTP id r19mr12398129wei.66.1335272215401; Tue, 24 Apr 2012 05:56:55 -0700 (PDT) Received: by 10.180.146.165 with HTTP; Tue, 24 Apr 2012 05:56:55 -0700 (PDT) In-Reply-To: <9570D903A3BECE4092E924C2985CE48555BEC3C2@MBX202.domain.local> References: <9570D903A3BECE4092E924C2985CE48555BEC3C2@MBX202.domain.local> Date: Tue, 24 Apr 2012 08:56:55 -0400 Message-ID: To: Clint M Priest Cc: "internals@lists.php.net" Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC: Property get/set syntax (added isset/unset and references) From: ircmaxell@gmail.com (Anthony Ferrara) Clint, Very nice job overall! Looking quite good. > Alternatively we could throw an error to a call on isset and/or unset ag= ainst 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() !=3D=3D 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 =3D 1; public $bar { get { return $this->bar; } set { $this->bar =3D (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 { > =A0 =A0private $Seconds =3D 3600; > > =A0 =A0public $Hours { > =A0 =A0 =A0 =A0get { return $this->Seconds / 3600; } > =A0 =A0 =A0 =A0set { $this->Seconds =3D $value; } > =A0 =A0 =A0 =A0isset { return !is_null($this->Seconds); } > =A0 =A0 =A0 =A0unset { $this->Seconds =3D NULL; } > =A0 =A0} > } > > References: > > > class SampleClass { > > =A0 =A0private $_dataArray =3D array(1,2,5,3); > > > > =A0 =A0public $dataArray { > > =A0 =A0 =A0 =A0&get { return &$this->_dataArray; } > > =A0 =A0} > > } > > > > $o =3D new SampleClass(); > > sort($o->dataArray); > > /* $o->dataArray =3D=3D array(1,2,3,5); */ > > Comments? > > These would also include automatic implementations which call the respect= ive functions on the backing field. =A0I could see only allowing isset/unse= t automatic implementations if get/set were also specified as automatic imp= lementations. > > Default implementations of isset/unset > > I'm also fielding comments/ideas on a way to always provide automatic imp= lementations of isset/unset for any accessor that didn't define one automat= ically. =A0One idea was for the isset (unspecified implementation) which wo= uld return true if the getter provided any value which evaluated to true, s= uch as this: > > class TimePeriod { > =A0 =A0private $Seconds =3D 3600; > > =A0 =A0public $Hours { > =A0 =A0 =A0 =A0get { return $this->Seconds / 3600; } > =A0 =A0 =A0 =A0set { $this->Seconds =3D $value; } > =A0 =A0} > } > /* Default Implementation Concept */ > > =A0 =A0 =A0 =A0isset { return (int)$this->Hours; } > =A0 =A0 =A0 =A0unset { $this->Hours =3D 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. =A0Alternatively we could throw an error to a call on i= sset and/or unset against a property which didn't define an implementation. > > Thoughts? > > -Clint