News Feed
Sections




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

Anthony Ferrara's Blog:
IteratorIterator - PHP Inconsistencies And WTFs
November 01, 2011 @ 12:58:07

Anthony Ferrara has a new post to his blog sharing some inconsistencies with iterators that he discovered as discussed with a fellow developer - why some iterators only accept Iterator arguments and others don't.

We were talking about why some of the SPL Iterators accept only an Iterator as the constructor argument (Such as LimitIterator), and others accept either an Iterator or an IteratorAggregate as the argument (Such as IteratorIterator). Feeling that this would be a useful feature to add (having all of them accept an IteratorAggregate), I opened up the PHP source and started looking at how hard of a change this would be. What I found was... Interesting...

He shares some of the C code he came across in his investigation including a "WTF" moment when he found a case statement for DIT_IteratorIterator in a constructor. Because of some of the logic in this constructor, the inputted iterator is "cast down" to a class. This is shown in a few code examples comparing simple iteration objects and arrays and how it seems to be able to bypass class inheritance to use methods from other classes.

0 comments voice your opinion now!
iterator iteratoriterator wtf constructor optional parameter class


blog comments powered by Disqus

Similar Posts

Stubbles Blog: My wishlist for PHP 6, pt1: The 'object' type hint

Zend Developer Zone: Avoiding XSS security attacks to sites that use HTML editors

PHPClasses.org Blog: Locating addresses on Google Maps embedded in PHP generated Web forms

Fabien Potencier's Blog: Iterator or IteratorAggregate?

DevShed: Introducing Builder Objects in PHP 5


Community Events





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


language symfony version tool example community conference security podcast voicesoftheelephpant opinion composer introduction release interview list framework library series laravel

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