Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:37508 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46655 invoked from network); 7 May 2008 06:13:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 May 2008 06:13:18 -0000 Authentication-Results: pb1.pair.com header.from=jeff@procata.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jeff@procata.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain procata.com from 207.58.169.145 cause and error) X-PHP-List-Original-Sender: jeff@procata.com X-Host-Fingerprint: 207.58.169.145 vps.procata.net Linux 2.5 (sometimes 2.4) (4) Received: from [207.58.169.145] ([207.58.169.145:53429] helo=vps.procata.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/C5-08231-A7841284 for ; Wed, 07 May 2008 02:13:16 -0400 Received: from adsl-63-201-158-210.dsl.snfc21.pacbell.net ([63.201.158.210] helo=[192.168.5.38]) by vps.procata.net with esmtp (Exim 4.68) (envelope-from ) id 1Jtctg-00039b-HM; Wed, 07 May 2008 02:13:00 -0400 Cc: Marcus Boerger , "John Carter -X (johncart - PolicyApp Ltd at Cisco)" , Derick Rethans , internals@lists.php.net Message-ID: <670D69DB-5C4D-4F24-94EE-BD40E6236803@procata.com> To: Lars Strojny In-Reply-To: <1210101672.3952.4.camel@localhost> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v919.2) Date: Tue, 6 May 2008 23:12:58 -0700 References: <48169695.9040803@omegavortex.net> <339714303.20080429114607@marcus-boerger.de> <7dd2dc0b0804290817v3d8de030y1208a88f78c44411@mail.gmail.com> <862660524.20080506162159@marcus-boerger.de> <912CE6DE-22D0-43E6-BB6B-6154980050E5@procata.com> <1210101672.3952.4.camel@localhost> X-Mailer: Apple Mail (2.919.2) X-ACL-Warn: { X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vps.procata.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - procata.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] Class Properties in Interfaces? From: jeff@procata.com (Jeff Moore) On May 6, 2008, at 12:21 PM, Lars Strojny wrote: > I think this is too unspecific. At least the visibility, setter and/or > getter and type-hint (assuming we will have type hints) should be > defined. Otherwise defining properties in interfaces become useless as > it does not tell somebody more except "there is a property". > > interface Something > { > public $property { > string public function get(); > string protected function set(string $value); > } > } Hi Lars, It isn't necessary to specify the visibility in an interface because all interface members are public. Specifying the accessor methods in an interface reveals too much of the implementation. Properties (the kind with accessor methods) are themselves an abstract concept. You want to be able to take an interface definition such as: interface foo { public $bar; // if you prefer this to abstract $foo; } and implement it like this: class DoIt implements foo { public $bar; } or to implement it using setters, using your notation: class DoIt2 implements foo { public $foo { public function get(); protected function set($value); } } The whole point of this kind of property is that the caller is never supposed to know if they are just accessing a object instance variable or an accessor method. This is called the uniform access principle. http://en.wikipedia.org/wiki/Uniform_access_principle Here is how C# handles properties in an interface: http://msdn.microsoft.com/en-us/library/64syzecx.aspx "The accessor of an interface property does not have a body. Thus, the purpose of the accessors is to indicate whether the property is read- write, read-only, or write-only." So, yeah, "there is a property named foo" is about all an interface should say. Best Regards, Jeff