Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35633 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 4658 invoked by uid 1010); 20 Feb 2008 00:20:51 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 4643 invoked from network); 20 Feb 2008 00:20:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Feb 2008 00:20:51 -0000 Authentication-Results: pb1.pair.com smtp.mail=jochem@iamjochem.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=jochem@iamjochem.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain iamjochem.com from 194.109.193.121 cause and error) X-PHP-List-Original-Sender: jochem@iamjochem.com X-Host-Fingerprint: 194.109.193.121 mx1.moulin.nl Linux 2.6 Received: from [194.109.193.121] ([194.109.193.121:35537] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/14-55225-2627BB74 for ; Tue, 19 Feb 2008 19:20:51 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id CF01B27E14B; Wed, 20 Feb 2008 01:20:47 +0100 (CET) X-Virus-Scanned: amavisd-new at moulin.nl Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (mx1.moulin.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kT3WXmS3IZiz; Wed, 20 Feb 2008 01:20:42 +0100 (CET) Received: from [10.0.13.105] (ip129-15-211-87.adsl2.versatel.nl [87.211.15.129]) by mx1.moulin.nl (Postfix) with ESMTP id 99F9827DA83; Wed, 20 Feb 2008 01:20:41 +0100 (CET) Message-ID: <47BB7259.3070205@iamjochem.com> Date: Wed, 20 Feb 2008 01:20:41 +0100 User-Agent: Thunderbird 2.0.0.9 (Macintosh/20071031) MIME-Version: 1.0 To: Lars Strojny CC: php@stefan-marr.de, internals@lists.php.net, =?ISO-8859-1?Q?=27Marcus?= =?ISO-8859-1?Q?_B=F6rger=27?= , =?ISO-8859-1?Q?=27Johanne?= =?ISO-8859-1?Q?s_Schl=FCter=27?= , 'Sebastian Bergmann' , 'Alexandre Bergel' , 'Falko Menge' , 'Sara Golemon' , derick@php.net References: <001c01c87264$3c01b4e0$b4051ea0$@de> <1203461114.24580.45.camel@localhost> <47BB6111.3080308@iamjochem.com> <1203464767.27871.4.camel@localhost> In-Reply-To: <1203464767.27871.4.camel@localhost> X-Enigmail-Version: 0.95.6 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC: Traits for PHP From: jochem@iamjochem.com (Jochem Maas) Lars Strojny schreef: > Hi Jochem, > > Am Mittwoch, den 20.02.2008, 00:06 +0100 schrieb Jochem Maas: > [...] >> if a trait would could contain all the methods required to implement >> an interface and a class uses it (the trait) and implements the >> relevant interface would it (the interface) be satified? > > Yes. The following should work: > interface IFoo { > public function method(); > } > > trait TFoo { > public functin method() { > echo "Hello World!"; > } > } > > class CFoo implements IFoo > { > use TFoo; > } > > This would be fine. > >> also might it be an idea to allow a trait to specify that it >> implements an interface for the purposes of development (errors >> triggered due to incorrect/incomplete implementation) >> BUT not have the interface be carried to any classes that use the >> trait? > > I don't see any sence in it. Why should one generalize an interface of a > trait? I don't suppose you would, I thinking more along the lines of having it a developer tool - using implements on a trait would force the developer to put in the correct methods, it might help a team that had say 1 interface, 2 traits (which both contain a set of methods that satify said interface) and a large number of classes that implement one or other of the traits ... having the trait state that it's capable of handling an implementation might save some WTF because compile time errors would happen on the trait if it broke the interface signature, rather than on the class ... an interface related error on the class it might not be obvious to the developer with regard to the fact that the/a trait the class is using was for the purpose of satifying an interface the class states it is implementing. I'm thinking that it will proably occur quite often that a fairly simple interface will be 'covered' by a trait and that said trait would be used solely for satifying said interface implementation and used as such for classes that wish to implement said interface. to quote Troels: "Class inheritance (The ``extends`` keyword) inherits type + implementation. Interface inheritance (The ``implements`` keyword) inherits type (but not implementation). Traits fill the missing hole by allowing inheritance of implementation, but not type." that sounds more than reasonable, but it might be worth offering an aid to developers during the compile time phase, with regard to the 'link' between a trait and an interface (assuming you would agree that it's not unlikely that the two would be used in tandem on occasion) without imposing/implying anything at run time (i.e. a trait may implement an interface to ensure correctness but that has no effect on any class that uses it, classes must explicitly state it's intention to implement an interface) I may have said something stupid - but given the ability of your average php user to stupid things with the functionality offered to him/her, my comments might aid in thrashing out such details in order to limit a user's ability to do stupid things :-) > > cu, Lars