php - Is it possible to implement an interface extending Traversable? -
i'd have iterable objects conforming interface leave choice of how implement iterability (implementing e.g. iterator
or iteratoraggregate
) implementation.
i thought might trick:
interface istraversable extends traversable { // other stuff here } class implements istraversable, iteratoraggregate { function getiterator() { return new arrayiterator(array()); } }
but throws:
class must implement interface traversable part of either iterator or iteratoraggregate
the message bit confusing iteratoraggregate
implemented. seems it's rather trying tell me cannot implement traversable
directly.
is possible implement requirement?
if extend traversable
, need list iteratoraggregate
first in list of implementations. per php manual:
this internal engine interface cannot implemented in php scripts. either iteratoraggregate or iterator must used instead. when implementing interface extends traversable, make sure list iteratoraggregate or iterator before name in implements clause.
emphasis mine. won't throw error:
<?php interface istraversable extends traversable { // other stuff here } class implements iteratoraggregate, istraversable { function getiterator() { return new arrayiterator(array()); } }
Comments
Post a Comment