Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50991 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 6761 invoked from network); 10 Dec 2010 16:49:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Dec 2010 16:49:51 -0000 Authentication-Results: pb1.pair.com header.from=quickshiftin@gmail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=quickshiftin@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.182 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: quickshiftin@gmail.com X-Host-Fingerprint: 209.85.215.182 mail-ey0-f182.google.com Received: from [209.85.215.182] ([209.85.215.182:56726] helo=mail-ey0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/68-59644-E2A520D4 for ; Fri, 10 Dec 2010 11:49:50 -0500 Received: by eyf6 with SMTP id 6so2952241eyf.13 for ; Fri, 10 Dec 2010 08:49:47 -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:cc:content-type; bh=4XPshc921eWpPCXJ/oFmPgffq+ONC4ylvGTulYsnWX8=; b=t5swPVv7VC3JU+cABU51ACJgllvzfhBuioPDBKOv2lbHGY0j0iNJ7uUeTLha01zsni oazDhe1X1hdrpbUcwzWNzTtRvMK+ZG5GNwu+SdRk+Tgtfte0sIw5Ej3QGmPXutExE6/5 BuRuM7K89b+n9HGWyUvOYKyFcyCA+pNaVTFqg= 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 :cc:content-type; b=wpb7m+wS3nKWxp7TUHvhchrz6AAas/UGUPuyX16ssrRRy/o8nxgGlNjyIfvXoIX+QZ fPEnz3biAoIkY15JoA5ymhQBlEyjvlQuiOJzodSMmYp8LIR2bGlQXeigITSM/o8fdTFJ /R249qZRmoBScY2jkpfi/EVdUOlqVq9Hs4tZg= MIME-Version: 1.0 Received: by 10.204.67.69 with SMTP id q5mr1010074bki.33.1291999786907; Fri, 10 Dec 2010 08:49:46 -0800 (PST) Received: by 10.204.112.208 with HTTP; Fri, 10 Dec 2010 08:49:46 -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:49:46 -0700 Message-ID: To: Stefan Marr Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=001636c5a9f659370404971124df Subject: Re: [PHP-DEV] Traits expecting interfaces implicitly leads to expensive runtime checks From: quickshiftin@gmail.com (Nathan Nobbe) --001636c5a9f659370404971124df Content-Type: text/plain; charset=UTF-8 On Thu, Dec 9, 2010 at 4:04 PM, Stefan Marr wrote: > 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. > > > > 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 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; > } > > } > Ahh, I see how the abstract methods are working in traits now, I didn't catch that from your first post; thanks for showing that to me. > You want to avoid the fatal error during runtime, right? > Yes, exactly, and the runtime check for expected interface / class / method. > Do you prefer dynamic checks over compile time checks? Def not :D, however, I still think this paradigm is lacking. Don't you think it makes more sense if I write a trait that expects a given interface or class to be able to specify said interface/class in it's entirety with just a single identifier rather than listing out all the methods? For example, I think this would be ugly essentially you're redeclaring the entire interface in the trait, the same would be true of the public interface of an expected class. i think it would be much more elegant to allow a specification on the trait declaration itself, something like -nathan --001636c5a9f659370404971124df--