Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50984 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39523 invoked from network); 9 Dec 2010 23:05:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2010 23:05:13 -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 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:39857] helo=uhweb12247.united-hoster.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 21/00-39391-7A0610D4 for ; Thu, 09 Dec 2010 18:05:11 -0500 Received: from cust194-138.dsl.as47377.net ([62.166.194.138] helo=[192.168.0.26]) by uhweb12247.united-hoster.com with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1PQpXH-0003hv-Ul; Fri, 10 Dec 2010 00:04:33 +0100 Mime-Version: 1.0 (Apple Message framework v1082) Content-Type: text/plain; charset=us-ascii In-Reply-To: Date: Fri, 10 Dec 2010 00:04:49 +0100 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <9A31F2F9-ED6B-4BE5-A6E2-EB4536E8667F@stefan-marr.de> References: <9CD87200-33CB-40BE-A81C-36FD7471F59C@stefan-marr.de> To: Nathan Nobbe X-Mailer: Apple Mail (2.1082) Subject: Re: [PHP-DEV] Traits expecting interfaces implicitly leads to expensive runtime checks From: php@stefan-marr.de (Stefan Marr) Hi Nathan: On 09 Dec 2010, at 23:42, Nathan Nobbe wrote: > What I'm getting at is the scenario when a trait is designed to be = used in > concert with the class in which it is being used. In this case the = trait > expects certain functions to be available on the class in which it is = used > with. If the methods aren't there (or checked for at runtime) a fatal = error > is raised. >=20 > A quick example > class A { > use AHelper; >=20 > function blah() {} > } >=20 > trait AHelper { > function meh() { > // hoping we get used w/ instances of A ... > return $this->blah() * 5; > } > } >=20 > class B { > use AHelper; >=20 > /// waiting for a runtime error if blah() is ever called .. > } > ?> >=20 > Do you see what I mean? No, do not really see what you are getting at. How is your approach using the instanceof checks (from the first mail) = different from changing AHelper to require blah() by stating this = requirement using an abstract method definition? For the trait it is not important where that method is implemented, it = just has to be in the final composed class. So, why don't you want the following trait? trait AHelper { abstract function blah(); function meh() { // hoping we get used w/ instances of A ... return $this->blah() * 5; } } You want to avoid the fatal error during runtime, right?=20 Do you prefer dynamic checks over compile time checks? Best regards Stefan --=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