Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35806 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 51169 invoked by uid 1010); 26 Feb 2008 03:19:19 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 51154 invoked from network); 26 Feb 2008 03:19:19 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Feb 2008 03:19:19 -0000 Authentication-Results: pb1.pair.com header.from=greg@chiaraquartet.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=greg@chiaraquartet.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain chiaraquartet.net from 38.99.98.18 cause and error) X-PHP-List-Original-Sender: greg@chiaraquartet.net X-Host-Fingerprint: 38.99.98.18 beast.bluga.net Linux 2.6 Received: from [38.99.98.18] ([38.99.98.18:35730] helo=mail.bluga.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/51-37363-63583C74 for ; Mon, 25 Feb 2008 22:19:18 -0500 Received: from mail.bluga.net (localhost.localdomain [127.0.0.1]) by mail.bluga.net (Postfix) with ESMTP id 82AA2C0FC76; Mon, 25 Feb 2008 20:19:15 -0700 (MST) Received: from [192.168.0.106] (CPE-76-84-4-101.neb.res.rr.com [76.84.4.101]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bluga.net (Postfix) with ESMTP id 0563BC0FC72; Mon, 25 Feb 2008 20:19:14 -0700 (MST) Message-ID: <47C3854B.1000303@chiaraquartet.net> Date: Mon, 25 Feb 2008 21:19:39 -0600 User-Agent: Thunderbird 2.0.0.6 (X11/20071022) MIME-Version: 1.0 To: php@stefan-marr.de CC: internals Mailing List , Marcus Boerger References: <47C317F4.2080301@stefan-marr.de> In-Reply-To: <47C317F4.2080301@stefan-marr.de> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV using ClamSMTP Subject: Re: How to build a real Trait thing without exclusion and renaming From: greg@chiaraquartet.net (Gregory Beaver) Stefan Marr wrote: > To get rid of exclude and rename I would like to propose the following: > > //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; > } > } This is far better than the original proposal. My only objection is that this introduces two new keywords, trait and instead. In addition, this can get very awkward if multiple traits (more than 2) implement the same method name. I would prefer a simple recycling of the "=" sign for both use cases (I'd also accept = for override, "as" for alias). class Talker { use A, B, C, D { smallTalk = A::smallTalk; // this says that if B, C or D implement smallTalk, it is ignored talk = A::bigTalk; } } To everyone - this is an aliasing procedure, not a renaming one, and won't affect internal methods of a trait (such as if B::whatever used B::smallTalk), as Richard Quadling incorrectly suggested. Greg