Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:63484 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80923 invoked from network); 17 Oct 2012 04:20:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2012 04:20:32 -0000 Authentication-Results: pb1.pair.com header.from=davidkmuir@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=davidkmuir@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.42 as permitted sender) X-PHP-List-Original-Sender: davidkmuir@gmail.com X-Host-Fingerprint: 209.85.160.42 mail-pb0-f42.google.com Received: from [209.85.160.42] ([209.85.160.42:46300] helo=mail-pb0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0C/12-64689-F023E705 for ; Wed, 17 Oct 2012 00:20:32 -0400 Received: by mail-pb0-f42.google.com with SMTP id ro2so6794719pbb.29 for ; Tue, 16 Oct 2012 21:20:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=9+diOCIa25KJzNcwYQ2Op48dqihtPWXdH+Mm58HtvSQ=; b=WSBWdTqv2jFe+s6MyLOaEOcVzwBtAXzQ1rC1KAxnAJxwdvQLNtBcYGrtgzwcXWmS9h BmDEzZ2cHHF3QnK2DuTf96fO9uX6Wb5pei3mFlz3MGcGl2y9g+XcTNVwDn6s8z6xsKgG 3cBv413x8jgZTkoKELg72Yg3Y39XA6B0ZYPk0vBtLHFWU8tTs9qa3zWimUd+K2Oq4O/j Utp64ohReobfpAPfX3nkVC7Dd4J+b5t1jAa47zttGuFDxXVCjTGWveBv7q77Cgbtao9c U2iHGRDAm6h/bFhHVVJdnPRUVMLR6pyKgxYqHnq0WENNGJc1vD8/U+wJNi8kh4DZiHiC rtqA== Received: by 10.68.218.132 with SMTP id pg4mr53292819pbc.100.1350447629247; Tue, 16 Oct 2012 21:20:29 -0700 (PDT) Received: from [192.168.1.181] (tmwpho1.lnk.telstra.net. [110.142.207.74]) by mx.google.com with ESMTPS id sz4sm11838523pbc.22.2012.10.16.21.20.26 (version=SSLv3 cipher=OTHER); Tue, 16 Oct 2012 21:20:28 -0700 (PDT) Message-ID: <507E3209.2050806@gmail.com> Date: Wed, 17 Oct 2012 15:20:25 +1100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 MIME-Version: 1.0 To: Clint Priest CC: Stas Malyshev , "Nikita Popov (nikita.ppv@gmail.com)" , "internals@lists.php.net" References: <9570D903A3BECE4092E924C2985CE485612B6466@MBX202.domain.local> <507D2AB5.1000903@sugarcrm.com> <9570D903A3BECE4092E924C2985CE485612B6C88@MBX202.domain.local> <507D3F8A.5040402@sugarcrm.com> <9570D903A3BECE4092E924C2985CE485612B6DF5@MBX202.domain.local> In-Reply-To: <9570D903A3BECE4092E924C2985CE485612B6DF5@MBX202.domain.local> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [PHP-DEV [RFC] Property Accessors v1.2 : Interfaces From: davidkmuir@gmail.com (David Muir) On 16/10/12 22:34, Clint Priest wrote: > >> -----Original Message----- >> From: Stas Malyshev [mailto:smalyshev@sugarcrm.com] >> Sent: Tuesday, October 16, 2012 6:06 AM >> To: Clint Priest >> Cc: Nikita Popov (nikita.ppv@gmail.com); internals@lists.php.net >> Subject: Re: [PHP-DEV] [PHP-DEV [RFC] Property Accessors v1.2 : Interfaces >> >> Hi! >> >>> that supports properties in interfaces. Again, not exhaustive either >>> but there is one language that does support accessors in interfaces >>> and that's C#. >> So what C# does when mixing regular properties and accessorized properties? > I'd have to do some research to know for sure, but it's highly likely that they cannot be mixed. >>> Think about it, if you allowed an outside caller of your class to >>> modify your internal state, any time you needed to use that internal >>> state you would have to validate it before you could rely upon its >>> value to be set correctly. No such issue exists with accessors in an >> I do not see why this assumption is made that I need to do some special validation each time state is changed. In fact, in 99% of >> existing code it is not happening, and I assume this ratio will be kept even when accessors are available. Most code will be very >> straightforward, not doing anything complex with the state. > If you have a public property $a which internally can only deal with it being set to 2 or 3 and someone external to the class sets it to 4, your class either has to check that it's 2 or 3 and deal with the fact that it is now 4 or have indeterminate results when it is set to 4. > >> Now, I think the bigger question is: what exactly you want to say/require when you write: >> >> interface a { public $xyz { get; } } >> >> and what is the use case for this requirement? > The use case is that you are declaring that interface a must allow a property $xyz to be readable and *not* writable. > >>> Just to be a bit more concrete here, as the code is presently written >>> and because I have strongly separated the concept of a property vs an >>> accessor, this code: >>> >>> interface a { public $xyz { get; } } >>> >>> class b implements a { public $xyz; } >>> >>> Produces the following error: Fatal error: Class b contains 3 abstract >>> accessors and must be declared abstract or implement the remaining >>> accessors (get a::$xyz, isset a::$xyz, ...) in %s on line %d >> I think this is wrong. 3 abstract accessors is especially wrong since it doesn't match the direct interface definition and is very >> confusing (see my earlier point about isset/unset always having fallback defaults) but even with get as abstract I do not see a valid >> use case that would require such behavior. What you want is for any $foo that is instanceof a to be able to respond to read request >> to $foo->xyz, right? Class b satisfies this requirement, why you reject it then? >> Also, if you reject it - how I should fix it to make it work? Would I have to implement a bolierplate getter/setter just to make >> interface work? Doesn't look like a good proposition to me. > Class b does not satisfy the requirement because you are missing the fact that public $xyz { get; } forbids setting of $xyz, only reading it. > That doesn't make sense. An implementation has to have the same or less restricted visibility, so the above should work. The inverse however should not: interface a { public $xyz; } class b implements a { public $xyz { get; }} Daivd