Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35626 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51554 invoked by uid 1010); 19 Feb 2008 23:07:07 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 51539 invoked from network); 19 Feb 2008 23:07:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Feb 2008 23:07:07 -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:48719] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A7/2E-55225-A116BB74 for ; Tue, 19 Feb 2008 18:07:07 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id 9DBB527E101; Wed, 20 Feb 2008 00:07:03 +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 7OaKUcnHuvl1; Wed, 20 Feb 2008 00:06:57 +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 5ADBE27DA83; Wed, 20 Feb 2008 00:06:57 +0100 (CET) Message-ID: <47BB6111.3080308@iamjochem.com> Date: Wed, 20 Feb 2008 00:06:57 +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> In-Reply-To: <1203461114.24580.45.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) Hi, Lars Strojny schreef: > Hi, > > Am Montag, den 18.02.2008, 20:27 +0100 schrieb php@stefan-marr.de: > [...] >> To underpin this relationship, it is possible to declare that a Trait >> implements an interface like this:: >> >> > interface IHello { >> public function sayHello(); >> } >> >> trait SayHello implements IHello { >> public function sayHello() { >> echo 'Hello World!'; >> } >> } >> >> class MyHelloWorld { >> use SayHello; >> } >> >> $o = new MyHelloWorld(); >> var_dump($o instanceof IHello); // bool(true) > > We have discussed that in IRC a bit and a lot of questions remain. The > most important issue to me how to handle interface implementations in > cases where methods from the interface implementing trait are renamed in > the trait consumer class. > I would propose to not overcomplicate things here and I see no real > advantage in allowing traits to implement interfaces. I think also for > the sake of conceptual integrity separating interfaces clearly from > traits is a good idea: interfaces define structure while traits are > function buckets. A class may use traits, may implement interfaces and > may extend another class. This paradigm is pretty easy to explain to the > user. 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? 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? ... classes would have to explicitly state that they implement the interface and the fact that they use a trait to do so would be irrelevant as far as 'where' the method came from. interface iFoo { function doFoo(); } // causes a compile time error due to missing function // trait tOneFoo implements iFoo { function doBar() { echo "hello"; } } // no compile time error // trait tTwoFoo implements iFoo { function doFoo() { echo "hello"; } } // using a trait that implements something without actually // taking on the implementation // class cOneFoo { uses tTwoFoo; } // any iFoo method exclusion, aliasing, renaming // in the following class would cause a compile time error // due to missing iFoo function unless the class itself // defined the method(s) in question // class cTwoFoo implements iFoo { uses tTwoFoo; } $one = new cOneFoo; $two = new cTwoFoo; // outputs: false, true var_dump( ($one instanceof iFoo), ($one instanceof iFoo) ); something like the above might offer developers desired OO strictness without actually blurring the boundaries between trait and interface conceptually. > > cu, Lars