Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50308 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92532 invoked from network); 17 Nov 2010 19:06:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2010 19:06:34 -0000 Authentication-Results: pb1.pair.com header.from=php@stefan-marr.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@stefan-marr.de; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain stefan-marr.de from 85.88.12.247 cause and error) X-PHP-List-Original-Sender: php@stefan-marr.de X-Host-Fingerprint: 85.88.12.247 toolslave.net Received: from [85.88.12.247] ([85.88.12.247:55497] helo=uhweb12247.united-hoster.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/C7-40885-8B724EC4 for ; Wed, 17 Nov 2010 14:06:33 -0500 Received: from [134.184.43.20] by uhweb12247.united-hoster.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1PInKo-00013Q-RZ; Wed, 17 Nov 2010 20:06:29 +0100 Mime-Version: 1.0 (Apple Message framework v1081) Content-Type: text/plain; charset=us-ascii In-Reply-To: Date: Wed, 17 Nov 2010 20:06:22 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <0461F658-378B-41D5-9521-B04EBB7F0C59@stefan-marr.de> References: To: Nathan Nobbe X-Mailer: Apple Mail (2.1081) Subject: Re: [PHP-DEV] Another question on traits From: php@stefan-marr.de (Stefan Marr) Hi Nathan: On 17 Nov 2010, at 19:06, Nathan Nobbe wrote: > So it sounds like implementing an interface directly with a trait has = been > shot down, Yes, Traits are meant to be compile-time only, they are not used to = introduce typing relationships.=20 > what I wonder about is will it still work if a class implements > an interface and uses a trait which provides the functions in said > interface? Yes, sure. >=20 > interface IHello { > public function sayHello(); > } >=20 > trait SayHello { > public function sayHello() { > echo 'hello world'; > } > } This is a typical pattern I would expect to see in code that uses = traits. You have an interface and then you provide a trait thats provide a = standard implementation for that interface. I would probably call the = trait similar to the interface HelloImpl or THello or so. >=20 > class MyHelloWorld implements IHello { > use SayHello; > } >=20 > $o =3D new MyHelloWorld(); > var_dump($o instanceof IHello); // bool (true) > ?> If that does not work, it is a bug I think. Best regards Stefan >=20 > thx, >=20 > -nathan --=20 Stefan Marr Software Languages Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://soft.vub.ac.be/~smarr Phone: +32 2 629 2974 Fax: +32 2 629 3525