Re: Traits expecting interfaces implicitly leads to expensive runtime checks
| From: | Stefan Marr | Date: | Fri, 10 Dec 2010 17:09:31 +0000 |
| Subject: | Re: Traits expecting interfaces implicitly leads to expensive runtime checks | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-50992@lists.php.net to get a copy of this message | ||
Hi Nathan:
On 10 Dec 2010, at 17:49, Nathan Nobbe wrote:
> 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
> <?php
> trait IteratorHelper{
> abstract public current();
> abstract public key();
> abstract public next();
> abstract public rewind();
> abstract public valid();
> }
> ?>
>
> 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
>
> <?php
> trait IteratorHelper expects Iterator {
> ...
> }
> ?>
:D That was exactly my thought when I was writing my first answer.
My second thought was, damn, not another keyword...
But since you also seem to see the need, we should give it a thought.
Anyone else with an opinion on that?
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