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
Nov 01, 2011 @ 17: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.

tagged: iterator iteratoriterator wtf constructor optional parameter class

Link:

Community News:
Launch of CSI:PHP
Jul 08, 2011 @ 15:08:12

Jeremy Kendall has started up a new blog that's a sort of "WTF in PHP" listing of some of the random (and bad) code that he comes across daily - CSI:PHP.

It all began with a new gig and an amazingly horrific codebase. I began tweeting the most unbelievable, most frustrating snippets I could find. After quite a few of those tweets, Chris Hartjes replied with, "Looking at your tweets I cannot even fathom what your job is. CSI:PHP ?" A concept was born.

Some of the posts so far include eval() hell, a bad use of preg_replace and a bad method for calling mail(). Currently there's not a way for others to contribute their own code WTFs, but from what I hear it's possible for the future.

tagged: csiphp wtf humor bad code

Link:


Trending Topics: