Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35811 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 64835 invoked by uid 1010); 27 Feb 2008 01:39:41 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 64820 invoked from network); 27 Feb 2008 01:39:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Feb 2008 01:39:41 -0000 X-Host-Fingerprint: 72.198.16.221 ip72-198-16-221.ok.ok.cox.net Received: from [72.198.16.221] ([72.198.16.221:8177] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/00-63317-B4FB4C74 for ; Tue, 26 Feb 2008 20:39:24 -0500 Message-ID: To: internals@lists.php.net Date: Tue, 26 Feb 2008 19:39:21 -0600 User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 References: <47C317F4.2080301@stefan-marr.de> In-Reply-To: <47C317F4.2080301@stefan-marr.de> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 080226-1, 02/26/2008), Outbound message X-Antivirus-Status: Clean X-Posted-By: 72.198.16.221 Subject: Re: How to build a real Trait thing without exclusion and renaming From: spam.goes.in.here@gmail.com (Joshua Thompson) Stefan Marr wrote: > //Example from the RFC with the cross-over conflict to be solved > trait A { > public function smallTalk() { > echo 'a'; > } > public function bigTalk() { > echo 'A'; > } > } > > trait B { > public function smallTalk() { > echo 'b'; > } > public function bigTalk() { > echo 'B'; > } > } > > //here the new notion of combing traits and resolving conflicts upfront > class Talker { > use A, B { > B::smallTalk instead A::smallTalk; > A::bigTalk instead B::bigTalk; > A::bigTalk as talk; > } > } Ok, let me give an example code and ask a few questions about it: trait A { public function smallTalk() { return 'a'; } public function bigTalk() { return strtoupper( $this->smallTalk() ); } } trait B { public function smallTalk() { return 'b'; } public function bigTalk() { return strtoupper( $this->smallTalk() ); } } class Talker { use A, B { B::smallTalk instead A::smallTalk; A::bigTalk instead B::bigTalk; A::bigTalk as talk; } } // now to the questions $talker = new Talker(); echo $talker->talk(); // What does this echo? My assumption is 'B'. echo $talker->bigTalk(); // How about this? echo $talker->smallTalk(); // This should be 'b'. All the discussion seems to be on not breaking a traits methods and to call internal methods from the trait. If this is the case, then the answer to the second question would be 'A', which would not break the trait's internal method call, but it seems less obvious to me. -- "Joshua Thompson"