Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65018 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 15385 invoked from network); 18 Jan 2013 01:42:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jan 2013 01:42:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=cpriest@zerocue.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=cpriest@zerocue.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zerocue.com designates 67.200.53.250 as permitted sender) X-PHP-List-Original-Sender: cpriest@zerocue.com X-Host-Fingerprint: 67.200.53.250 mail.zerocue.com Received: from [67.200.53.250] ([67.200.53.250:48267] helo=mail.zerocue.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F9/00-14349-498A8F05 for ; Thu, 17 Jan 2013 20:42:45 -0500 Received: from [172.17.0.122] (unknown [70.112.216.188]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mail.zerocue.com (Postfix) with ESMTPSA id 4CA3912037B; Fri, 18 Jan 2013 01:42:42 +0000 (UTC) Message-ID: <50F8A88D.1000409@zerocue.com> Date: Thu, 17 Jan 2013 19:42:37 -0600 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: Steve Clay CC: PHP Internals References: <50F840F4.7080704@zerocue.com> <50F87A23.60808@mrclay.org> In-Reply-To: <50F87A23.60808@mrclay.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [VOTE] Property Accessors for 5.5 From: cpriest@zerocue.com (Clint Priest) On 1/17/2013 4:24 PM, Steve Clay wrote: > > https://wiki.php.net/rfc/propertygetsetsyntax-v1.2#voting > > I'll say my peace on this. This is a very good implementation, and as > long as authors use accessors that depend on a separate property for > storage (like other langs require), everything will be > straightforward. Otherwise, I fear they're in for some confusing > behavior. > > Consider the code from the RFC: > > class TimePeriod { > public $Hours { > get { return $this->Hours ?: "not specified"; } > set { $this->Hours = $value; } > } > } > > $tp = new TimePeriod(); > $tp->Hours; // "not specified" > isset($tp->Hours); // true!? > $tp->Hours isset, the property exists and it's value is non-null. > The auto implementation of isset compares $this->Hours to NULL, but > since $this->Hours goes through the getter, it will return "not > specified". So the property will always appear to be isset. > > * The guards seem spooky: A set of tokens ($this->prop) will have > varying behavior (e.g. direct prop read vs. getter call) *depending on > the call stack*. This is the same as would occur with isset against an undefined property, that would call __isset(), followed by __get() which would then compare the value to NULL. > > * Giving issetter/unsetter no direct access to the property limits > functionality and leads to weirdness like the example above. > This is possible, simply by supplying your own implementation of isset/unset that calls isset/unset, such as: public $foo { get; set; isset { return isset($this->foo); } unset { unset($this->foo); } } The above five lines of code is exactly equivalent in functionality to: public $foo; -Clint