News Feed
Jobs Feed
Sections




News Archive
Web Mozarts:
Give the Traversable Interface Some Love
October 10, 2012 @ 09:12:56

In this recent post to the Web Mozarts site, Bernhard Schussek "gives Traversable some love" and introduces you to the Traversable interface and how it might work better for certain things than an Iterator.

Let's start with a simple use case. Let's create an interface ArrayInterface that demarcates objects that behave like PHP arrays. The interface should allow for counting, iterating and array access.

He shows how to create this interface based off of a "ArrayInterface" that implements "Countable", "ArrayAccess" and "Iterator" with all of the methods required for each. He points out that, while the documentation in the manual makes "Traversable" shouldn't be used, it can be extended instead of Iterator. This gives other classes that extend this interface the option of extending either of the Iterators ("Iterator" or "IteratorAggregate") they want.

0 comments voice your opinion now!
interface traversable introduction iterator iteratoraggregate


blog comments powered by Disqus

Similar Posts

IBM developerWorks: PHP frameworks, Part 1: Getting started with three popular frameworks

Zend Developer Zone: Getting Started with Drizzle and PHP

PHPit.net: Using the CURL Library on PHP

PHPMaster.com: What's New in Zend Framework 2

Michael Nitschinger's Blog: Handling JSON like a boss in PHP


Community Events











Don't see your event here?
Let us know!


series database podcast zendframework2 api opinion example interview composer framework testing code functional application language release development phpunit introduction community

All content copyright, 2013 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework