Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50990 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2357 invoked from network); 10 Dec 2010 06:18:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2010 06:18:56 -0000 Authentication-Results: pb1.pair.com header.from=crocodile2u@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=crocodile2u@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.216.42 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: crocodile2u@gmail.com X-Host-Fingerprint: 209.85.216.42 mail-qw0-f42.google.com Received: from [209.85.216.42] ([209.85.216.42:51502] helo=mail-qw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FC/C3-09391-F46C10D4 for ; Fri, 10 Dec 2010 01:18:55 -0500 Received: by qwj8 with SMTP id 8so3547570qwj.29 for ; Thu, 09 Dec 2010 22:18:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type; bh=r6z+vdm1gNonlnOx1UQoDHItKwfotRBUTOpCTf45zJw=; b=W3Rr1PsSMNh5PbFKBuXlI3rzZNmlgsXFFPLI8s2zq3K4uk3fy0KuiSdTlbTxHZ07UK DYmq3EXwzc0vWcpCE9us4NcwbYu4BioMRrUykxoxwOUg5VqWSvCX2RZ5iapV1X3opBwN fIEerWrOMkVPp15mkcCc/uuOFz9lqBpYJ2Lmk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=fOemoQAI+/PlZ6RV2ewgt3xpXgc2aEcA+HYnynJvoWoiOhGoAP+42O1oUhbuDJ0CMb kRTQJb6AJydgkR9+eDMXE8QMSJlCQoWh4NibPrN7pYkN6L4LP6fJo5MJ+JGDb7ZlR0w/ dyj52A96Ve/69q8a7swFC1KhUL8tjYJdtoiys= MIME-Version: 1.0 Received: by 10.229.215.136 with SMTP id he8mr288798qcb.111.1291961932743; Thu, 09 Dec 2010 22:18:52 -0800 (PST) Received: by 10.229.241.66 with HTTP; Thu, 9 Dec 2010 22:18:52 -0800 (PST) In-Reply-To: <9A31F2F9-ED6B-4BE5-A6E2-EB4536E8667F@stefan-marr.de> References: <9CD87200-33CB-40BE-A81C-36FD7471F59C@stefan-marr.de> <9A31F2F9-ED6B-4BE5-A6E2-EB4536E8667F@stefan-marr.de> Date: Fri, 10 Dec 2010 09:18:52 +0300 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=0016363104511082bb04970854c7 Subject: Re: [PHP-DEV] Traits expecting interfaces implicitly leads to expensive runtime checks From: crocodile2u@gmail.com (Victor Bolshov) --0016363104511082bb04970854c7 Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: quoted-printable Personally, I believed that traits are a *compile time injection* to a class, so that at runtime a class behaves completely as it would if trait methods were implemented directly in the class. That said, everything like trait requirements for a certain interface, should be done at compile time and constructions like abstract foo(); in a trait serve that purpose. IMHO. 2010/12/10 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 tra= it > > 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. > > > > A quick example > > > class A { > > use AHelper; > > > > function blah() {} > > } > > > > trait AHelper { > > function meh() { > > // hoping we get used w/ instances of A ... > > return $this->blah() * 5; > > } > > } > > > > class B { > > use AHelper; > > > > /// waiting for a runtime error if blah() is ever called .. > > } > > ?> > > > > 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 ju= st > 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? > > Do you prefer dynamic checks over compile time checks? > > Best regards > Stefan > > -- > 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 > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --=20 =F3 =D5=D7=C1=D6=C5=CE=C9=C5=CD, =F7=C9=CB=D4=CF=D2 --0016363104511082bb04970854c7--