Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55849 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 65726 invoked from network); 17 Oct 2011 18:00:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Oct 2011 18:00:48 -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 81.20.134.149 cause and error) X-PHP-List-Original-Sender: php@stefan-marr.de X-Host-Fingerprint: 81.20.134.149 vps-1012701-4512.united-hoster.de Received: from [81.20.134.149] ([81.20.134.149:60737] helo=vps-1012701-4512.united-hoster.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A1/EB-27630-54D6C9E4 for ; Mon, 17 Oct 2011 14:00:40 -0400 Received: from d51a4d67f.access.telenet.be ([81.164.214.127] helo=[192.168.0.21]) by vps-1012701-4512.united-hoster.de with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1RFrUD-0003bb-4x; Mon, 17 Oct 2011 20:00:30 +0200 Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=iso-8859-1 In-Reply-To: Date: Mon, 17 Oct 2011 20:00:22 +0200 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Ferenc Kovacs X-Mailer: Apple Mail (2.1084) Subject: Re: typehinting traits From: php@stefan-marr.de (Stefan Marr) Hi Ferenc: On 17 Oct 2011, at 19:41, Ferenc Kovacs wrote: > Hi Stefan, >=20 > Multiple people asked me that how they can expect/check that a given = object uses a trait or not. > Of course one could write the concrete methods as a trait and always = use a given interface for typehints, but I can't see why shouldn't = instanceof and typehints in general work for traits. > Is the any technical or maybe theoretical argument against this?=20 Originally I proposed traits including the semantics that traits = directly implement interfaces. The discussion is somewhere here: = http://www.mail-archive.com/internals@lists.php.net/msg33935.html I think Sebastian was the person with the strongest opinion on that = particular issue: http://www.mail-archive.com/internals@lists.php.net/msg33948.html And I tend to agree with him. Currently I think along the following lines: A trait is not a full unit of reuse! A class is.=20 Don't use traits where you should use classes and composition. Traits do not guarantee anything, if you want to be sure your = invariants hold, use classes and composition. Traits allow to reuse behavior in a much more flexible way, but they = do not replace classes. And, well, then there is this: = https://wiki.php.net/rfc/horizontalreuse#requiring_composing_class_to_impl= ement_interface That should make sure that people can use interfaces for the purpose = envisioned here. For reference, there is also: https://bugs.php.net/bug.php?id=3D55613 But aside of the things I said before: - theoretically: keeping interfaces and traits apart is a good, clean = language design decision. - practically: people LOVE ugly languages, because they get things done So, well, I can't claim anything about value here. The current situation might be more friendly to the teacher. Another design might offer more freedom/power...=20 Best regards Stefan >=20 > --=20 > Ferenc Kov=E1cs > @Tyr43l - http://tyrael.hu --=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