News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

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

PHPBuilder.com: The ABC's of PHP II - What do I need to make it work?

PHPBuilder.com: The ABC's of PHP Part 4 - How Variable Am I?

NetTuts.com: Building Web Applications from Scratch with Laravel

Mushfiqsimple Blog: Getting Started with MongoDb with PHP

Mike Potter's Blog: Introduction to Adobe Flex Builder for PHP Developers


Community Events





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


install tool framework podcast introduction composer library laravel security community series update interview version release symfony voicesoftheelephpant opinion language package

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