Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50983 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36510 invoked from network); 9 Dec 2010 22:42:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2010 22:42:47 -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.214.45 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.214.45 mail-bw0-f45.google.com Received: from [209.85.214.45] ([209.85.214.45:61876] helo=mail-bw0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4B/F0-26210-66B510D4 for ; Thu, 09 Dec 2010 17:42:47 -0500 Received: by bwz16 with SMTP id 16so3490074bwz.32 for ; Thu, 09 Dec 2010 14:42:43 -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=lCrW3oaaZqJB9r6d/02gptj521dtCul8wXWfT8OuOaE=; b=ap7i76sXMEouzjs1J5ClmRoy44Tz7Q46Fi9cTbAijXIHrTceoHg8YmUcIEtn2vYngy ou18hhNmON+8u2yTBuf5J6JhqcY4ychWRawjJSq4VfRlNbnVKNRQQZ6zB7F/qd1HeYCs SbAaN1gIvEq3GtJ8CwdQizuzo/hLSKxjz+evk= 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=HETWLnSrO4DhEb3tNjzwsqC9oTuQ8pRON2AqHsd1fhTYlV+S3JZLTjZW12WjNzfm1d nZT5Y7xoR0aH7fWubRa0xAohozcITic5eCT8epvIN0ZtUa7b31ob0Qut0vK5n14p0SNr XVm86RVP9cwWBYWjrq2ZS4XhkS6k70yhl/UO8= MIME-Version: 1.0 Received: by 10.204.118.7 with SMTP id t7mr14216bkq.87.1291934563579; Thu, 09 Dec 2010 14:42:43 -0800 (PST) Received: by 10.204.112.208 with HTTP; Thu, 9 Dec 2010 14:42:43 -0800 (PST) In-Reply-To: <9CD87200-33CB-40BE-A81C-36FD7471F59C@stefan-marr.de> References: <9CD87200-33CB-40BE-A81C-36FD7471F59C@stefan-marr.de> Date: Thu, 9 Dec 2010 15:42:43 -0700 Message-ID: To: Stefan Marr Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=001636c5a772bc39cc049701f411 Subject: Re: [PHP-DEV] Traits expecting interfaces implicitly leads to expensive runtime checks From: quickshiftin@gmail.com (Nathan Nobbe) --001636c5a772bc39cc049701f411 Content-Type: text/plain; charset=UTF-8 On Thu, Dec 9, 2010 at 1:09 AM, Stefan Marr wrote: > Hi Nathan: > > On 09 Dec 2010, at 08:44, Nathan Nobbe wrote: > > > Hi, > > > > I think traits will lend themselves to frequent runtime checking against > the > > type of class in which they were used. Consider a trait designed for use > > with an Iterator class; the first thing might be to check the type of > $this. > Why would you need such a check? > To avoid a fatal error at runtime. > You want to ensure that the class that is using your trait obeys a certain > interface, right? > Not really, it's so the trait can guarantee the class it has been used with implements a given interface that it may need to accomplish its job. > More specifically, you need it to implement a number of methods of an > interface, correct? > So, why not asking for it explicitly? > > trait InnerIteratorImpl { > abstract function next(); > > public function apply() { > do somthing with $this->next() ... > } > } > ?> > > Does that what you want it to do? > Not really, in this example above the trait is self-contained, implementing all the methods of a particular interface so it's reasonable to expect from one of the methods in the trait, another of the Iterator interface to be there. 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 blah() * 5; } } class B { use AHelper; /// waiting for a runtime error if blah() is ever called .. } ?> Do you see what I mean? -nathan --001636c5a772bc39cc049701f411--