News Feed
Sections




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

Jeremy Cook's Blog:
Implementing IteratorAggregate and Iterator
May 14, 2012 @ 13:04:58

In a recent post to his blog Jeremy Cook has gotten back into looking at some of the SPL functionality that comes with PHP. In this new post he looks specifically at the IteratorAggregate and Iterator object types.

After a bit of a break I'm finally able to get back to writing about the predefined interfaces in PHP. PHP provides two interfaces that allow you to define how your objects behave in a foreach loop: IteratorAggregate and Iterator. Before taking a look at IteratorAggregate I'll briefly discuss how we can iterate over objects in PHP 'natively' and what it means to be Traversable.

He introduces the concepts being being "iteratable" and "traversable". He then shows how to implement the IteratorAggregate (only one method required, "getIterator") and Iterator ("next", "valid", "current" and "key" methods required) in classes of your own.

You can find out more about these two object types (including more sample usage) on their manual pages: IteratorAggregate & Iterator.

0 comments voice your opinion now!
iteratoraggregate iterator tutorial iterate traversable


blog comments powered by Disqus

Similar Posts

Version Control Blog: Upgrading Drupal with Git

DevShed: Designing a Captcha System with PHP and MySQL

HowTo Forge: Installing Lighttpd With PHP5 And MySQL Support On Mandriva 2008.0

Web Development Blog: Upload images for usage in TinyMCE

Hasin Hayder's Blog: RSA Encrypting and Decrypting data with Zend_Crypt_Rsa Library


Community Events





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


release developer community podcast introduction threedevsandamaybe framework series list application code project interview api configure bugfix library language laravel wordpress

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