Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:35799 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94259 invoked by uid 1010); 25 Feb 2008 19:19:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 94244 invoked from network); 25 Feb 2008 19:19:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2008 19:19:33 -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:41716] helo=serv6.servweb.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2F/27-11428-3C413C74 for ; Mon, 25 Feb 2008 14:19:32 -0500 Received: from [192.168.0.25] (toolslave.net [85.88.12.247]) by serv6.servweb.de (Postfix) with ESMTP id 8F28D5903C6; Mon, 25 Feb 2008 20:21:04 +0100 (CET) Message-ID: <47C314CA.3060605@stefan-marr.de> Date: Mon, 25 Feb 2008 20:19:38 +0100 Reply-To: php@stefan-marr.de User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 To: Stanislav Malyshev Cc: internals@lists.php.net References: <001c01c87264$3c01b4e0$b4051ea0$@de> <698DE66518E7CA45812BD18E807866CE014A8D9D@us-ex1.zend.net> <342791187.20080225104951@marcus-boerger.de> <47C2D8C5.2000401@stefan-marr.de> <47C2E9A1.5090708@zend.com> In-Reply-To: <47C2E9A1.5090708@zend.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Redirected: By TestProxy Subject: Re: [PHP-DEV] RFC: Traits for PHP From: php@stefan-marr.de (Stefan Marr) Hi, Stanislav Malyshev schrieb: > What I still don't understand it's how you can solve these conflicts at > all. I.e., suppose you have Counter API and DBConnection API on each of > which you have clean() method - for Counter it resets it to zero and for > DB it resets authentication details. How it is possible to resolve it in > any way so that resulting class would support both APIs? Would exactly do you mean with API? And how would you solve this problem without traits? Traits can not solve stuff like colliding methods with colliding semantics in interfaces. One solution would be to do the following: trait Counter { public function clean() { $this->setCntValue(0); } } trait DBConnection { public function clean() { // one problem we probably should not // discuss here is the naming, think it // should be named resetCredentials $this->setCredentials(null); } } class DBCounter { use Counter { !clean, cleanCounter => clean } use DBConnection { !clean, resetCredentials => clean } } This would be a class reusing the behavior implemented in both traits, and this is the contribution of the traits idea. With mixins this wouldn't be possible and C++ multiple-inheritance would introduce fragility. If DBCounter should implement ICounter and IDBConnection with each having a clean method, there is no meaningful possible implementation within a single class. Since the semantics of the two clean methods are not as near as it would be necessary. and a class DBCounter { use Counter { !clean, cleanCounter => clean } use DBConnection { !clean, resetCredentials => clean } public function clean() { $this->cleanCounter(); $this->resetCredentials(); } } would be a bit pointless, but possible... Kind Regards Stefan