Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65040 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64080 invoked from network); 20 Jan 2013 14:21:10 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2013 14:21:10 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.22 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.22 smtp2.ist.utl.pt Linux 2.6 Received: from [193.136.128.22] ([193.136.128.22:37456] helo=smtp2.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0A/92-25745-45DFBF05 for ; Sun, 20 Jan 2013 09:21:09 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 7581070003D1; Sun, 20 Jan 2013 14:21:05 +0000 (WET) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp2.ist.utl.pt ([127.0.0.1]) by localhost (smtp2.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id DOhOcMSxMC3I; Sun, 20 Jan 2013 14:21:05 +0000 (WET) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp2.ist.utl.pt (Postfix) with ESMTP id 11C3D700045F; Sun, 20 Jan 2013 14:21:05 +0000 (WET) Received: from damnation.nl.lo.geleia.net (a80-101-138-144.adsl.xs4all.nl [80.101.138.144]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 9A50E2007325; Sun, 20 Jan 2013 14:21:04 +0000 (WET) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Sherif Ramadan" Cc: "Nikita Popov" , "Clint Priest" , "Steve Clay" , "PHP Internals" References: <50F840F4.7080704@zerocue.com> <50F87A23.60808@mrclay.org> <50F8A88D.1000409@zerocue.com> Date: Sun, 20 Jan 2013 15:21:03 +0100 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/12.12 (Linux) Subject: Re: [PHP-DEV] [VOTE] Property Accessors for 5.5 From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") On Sun, 20 Jan 2013 14:52:36 +0100, Sherif Ramadan wrote: >> I think the current behavior is most appropriate one for var_dump() (and >> array casts/get_object_vars()). It's the same behavior as if you had >> manually defined getXXX() methods or used __get(). >> > It's actually not the same behavior at all. __get can only work on > inaccessible properties. So I would not see NULL there in the object and > then get a value in the instance property. OK, it's not 100% analogous. And I'm ready to concede that the differences that do exist may be (arguably) sufficient to draw a principled distinction, namely: * getXXX() is clearly a method call and not a (direct) property read and the XXX property may not even exist. * __get() only works on inaccessible properties, so there is no possible confusion. I still think you put too much emphasis on the __get() argument -- even though there is no accessible property, there may be a protected/private property; it it isn't the case, there's still usually some backing storage, like a private array (shown in var_dump()) and the backing value may be different from what's returned. In any case, assuming this feature is accepted, the current solution, whether in isolation it's appropriate or not, must be evaluated in the light of the alternatives. Here, I thought you were proposing calling the getters. >> If you start marking function calls, you get new problems like handling >> getters that throw exceptions or have side effects ("the code behaves >> differently when add a var_dump()?!"). > > > I'm not suggesting the getters should be invoked from afar. I'm just > suggesting some additional means of informing the user of the existence > of that getter to distinguish it from the property in the output of > var_dump. > > So for example, in var_dump, you can get ["property":protected] => ... > when the property has a visibility outside of the current context. It > might be > helpful to provide some similar behavior for accessors with null > initialized values, but have getters available to the caller? We could add some sort of marker to indicate the property is an accessor. It would not be trivial under the current implementation as get_properties() and get_debug_info() only return a HashTable*, so some abstraction breaking would be required. Another possibility would be the ability to mark some properties as not backed by any storage, like the area in your example. But this would still be insufficient to eliminate confusion in cases like this: class A { private $scale; public $value { get { return $this->value * $this->scale; } set; } function __construct($scale) { $this->scale = (double)$scale; } } -- Gustavo Lopes