Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35761 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85120 invoked by uid 1010); 23 Feb 2008 20:40:21 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 85105 invoked from network); 23 Feb 2008 20:40:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Feb 2008 20:40:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@stefan-marr.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@stefan-marr.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain stefan-marr.de from 82.96.83.42 cause and error) X-PHP-List-Original-Sender: php@stefan-marr.de X-Host-Fingerprint: 82.96.83.42 serv6.servweb.de Linux 2.4/2.6 Received: from [82.96.83.42] ([82.96.83.42:47391] helo=serv6.servweb.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D1/35-30812-4B480C74 for ; Sat, 23 Feb 2008 15:40:21 -0500 Received: from [192.168.0.25] (toolslave.net [85.88.12.247]) by serv6.servweb.de (Postfix) with ESMTP id 751FC590015; Sat, 23 Feb 2008 21:41:50 +0100 (CET) Message-ID: <47C084B7.80007@stefan-marr.de> Date: Sat, 23 Feb 2008 21:40:23 +0100 Reply-To: php@stefan-marr.de User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: Christian Schneider Cc: internals Mailing List References: <47BD207C.2080905@chiaraquartet.net> <47BD928E.8080006@cschneid.com> In-Reply-To: <47BD928E.8080006@cschneid.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Redirected: By TestProxy Subject: Re: [PHP-DEV] Re: Trait aliasing syntax suggestions From: php@stefan-marr.de (Stefan Marr) Hi, Christian Schneider schrieb: > I can see two > use cases for aliasing: > 1) An interface uses a different name than the > trait implements. Not sure that's a software design problem trait should > try to solve. Well, no, aliasing shouldn't be used to achieve this, think it would be better to add some glue code to a class to fulfill a interface, i.e. add a new method which will call the method from the trait if the name of the traits method does not fit to the interface. This will avoid confusion about the next point you've named. (for simple situations exclude and aliasing will do the job as well, yes) > 2) There is a clash with an existing function in the > class. Then one would have to both alias and exclude the trait function > name anyway (which is the same as renaming) PLUS you'd have the problem > of trait classes calling the 'wrong' functions again. In my opinion it is not a problem, but an opportunity. For a situation where two traits are implementing stuff which is very closely related and will be combined in a class you can do the following: trait A { public function handle($something) { $this->process($something); } protected function process($something) { // ... } } trait B { protected function process($something) { // a method to process $something and be reused // interdependently at several places } } class Processor { use A { processA => process } use B { processB => process } protected function process($something) { // do combined processing using both traits methods $this->processA($something); $this->processB($something); } } Kind Regards Stefan