<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Sun, 12 Feb 2012 21:01:51 -0600</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Jake Smith's Blog: Callback Filter Iterator in PHP 5.3/5.4]]></title>
      <guid>http://www.phpdeveloper.org/news/17202</guid>
      <link>http://www.phpdeveloper.org/news/17202</link>
      <description><![CDATA[<p>
<i>Jake Smith</i> has a new post to his blog today about a feature included in PHP's <a href="http://php.net/spl">Standard PHP Library</a> that you might have overlooked - <a href="http://jakefolio.com/2011/12/callback-filter-iterator-in-php/">the FilterIterator's callback functionality</a>.
</p>
<blockquote>
The Filter Iterator is probably my second favorite iterator, next to Directory Iterator.  There are many great use cases for the Filter Iterator, and when you do filter the original data is left untouched. A Filter Iterator is really simple to use, create a class that extends FilterIterator and adjust the accept method to meet your criteria.  This is great and all, but having the ability to create filter iterators on the fly, ones that won't be used application wide, without having to create a class is even better.
</blockquote>
<p>
He includes a bit of code defining a FilterCallbackIterator class with a "callback" parameter passed into the constructor (in his case, a closure). Also included is some sample code of it in use - handling an array (well, ArrayIterator) with a simple true/false check on the current array value. You can find out more about this functionality in <a href="http://www.php.net/manual/en/class.callbackfilteriterator.php">the PHP manual</a>.
</p>]]></description>
      <pubDate>Fri, 02 Dec 2011 08:44:34 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Anthony Ferrara's Blog: IteratorIterator - PHP Inconsistencies And WTFs]]></title>
      <guid>http://www.phpdeveloper.org/news/17071</guid>
      <link>http://www.phpdeveloper.org/news/17071</link>
      <description><![CDATA[<p>
<i>Anthony Ferrara</i> has a new post to his blog sharing some <a href="http://blog.ircmaxell.com/2011/10/iteratoriterator-php-inconsistencies.html">inconsistencies with iterators</a> that he discovered as discussed with a <a href="http://twitter.com/#!/go_oh">fellow developer</a> - why some iterators only accept Iterator arguments and others don't.
</p>
<blockquote>
We were talking about why some of the SPL Iterators accept only an Iterator as the constructor argument (Such as <a href="http://us2.php.net/manual/en/class.limititerator.php">LimitIterator</a>), and others accept either an Iterator or an IteratorAggregate as the argument (Such as <a href="http://us2.php.net/manual/en/class.iteratoriterator.php">IteratorIterator</a>).  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...
</blockquote>
<p>
He shares some of the C code he came across in his investigation including a "WTF" moment when he found a <a href="http://lxr.php.net/xref/PHP_5_3/ext/spl/spl_iterators.c#1418">case statement for DIT_IteratorIterator</a> 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.
</p>]]></description>
      <pubDate>Tue, 01 Nov 2011 12:58:07 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: Implementing the ArrayAccess Interface - PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16483</guid>
      <link>http://www.phpdeveloper.org/news/16483</link>
      <description><![CDATA[<p>
In the first part of a new series over on DevShed.com, they introduce the concept of "segregated interfaces" and show how to use them <a href="http://www.devshed.com/c/a/PHP/Segregated-Interfaces-in-PHP/1/">to work with collections of arrays</a> (using interfaces that are a part of the <a href="http://php.net/spl">SPL</a>).
</p>
<blockquote>
To start illustrating why segregated interfaces are really useful, in the lines to come I'm going to build an example that will recreate the scenario described in the introduction. Basically, what I want to achieve here is to construct a custom countable array collection.
</blockquote>
<p>
He shows the basic class structure needed to emulate a countable array in an object by implementing the "Countable" interface. He adds in the "Iterator" interface to allow you to work with the dataset like an array - progressing through it, rewinding to the beginning and checking to see if a value exists. Finally, they add the "ArrayAccess" interface to the class that boosts it with even more features like the ability to grab things by specific keys (numeric or string). The finish the article off with an example of an ArrayCollection object and how it can be looped through using a <a href="http://php.net/foreach">foreach</a>.
</p>]]></description>
      <pubDate>Fri, 17 Jun 2011 08:58:04 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Web Species Blog: Lazy evaluation with PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16410</guid>
      <link>http://www.phpdeveloper.org/news/16410</link>
      <description><![CDATA[<p>
<i>Juozas Kaziukenas</i> has a new post to his Web Species blog about <a href="http://blog.webspecies.co.uk/2011-05-31/lazy-evaluation-with-php.html">using "lazy evaluation" in PHP</a> - loading the resources you need for execution and evaluation only as you need them, not all up front.
</p>
<blockquote>
Recently I needed to process a huge array of data and because of PHP's somewhat inefficient variables and especially arrays that was resulting in "out of memory" errors. However, I couldn't use any other tools than PHP so was forced to come up with a solution implementation in it. Here is how I solved it using principles from functional languages.
</blockquote>
<p>
He gives an example using Haskell to generate a Fibonacci sequence using its built-in lazy evaluation abilities. Unfortunately, PHP doesn't have such a thing built in, so he tries the next best thing - <a href="http://php.net/manual/en/class.iterator.php">Iterators</a>. He caries the idea over to the database side too, recommending fetch() in a loop over fetchAll() and some effective joins.
</p>]]></description>
      <pubDate>Wed, 01 Jun 2011 08:41:01 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[SitePoint PHP Blog: Sophisticated Object Iterators in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16301</guid>
      <link>http://www.phpdeveloper.org/news/16301</link>
      <description><![CDATA[<p>
Following up on their earlier <a href="http://phpdeveloper.org/news/16267">simple object iterators</a> post, the SitePoint PHP blog is back with a look at <a href="http://blogs.sitepoint.com/php-object-iterators/">more sophisticated iterators</a> you can use to work with database record objects.
</p>
<blockquote>
In my previous post, <a href="http://blogs.sitepoint.com/php-simple-object-iterators">Simple Object Iterators in PHP</a>, we discovered how to iterate over array items defined within an object using a <a href="http://php.net/manual/en/control-structures.foreach.php">foreach loop</a>. However, what if you need to iterate over items which are not stored in an array, e.g. records from a database or lines of text read from a file?
</blockquote>
<p>
He shows how to create a script that pulls in the users from a database object (PDO, in this case) and implements the Countable and Iterator interfaces. These interfaces give it some special methods that can give counts of the results and help you iterate through the results - current, rewind, next and valid. 
</p>]]></description>
      <pubDate>Thu, 05 May 2011 12:54:59 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[SitePoint PHP Blog: Simple Object Iterators in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16267</guid>
      <link>http://www.phpdeveloper.org/news/16267</link>
      <description><![CDATA[<p>
On the SitePoint PHP blog today there's a new post from <i>Craig Buckler</i> looking (quickly) at a handy feature of the Standard PHP Library (SPL) that can help make working with objects and arrays simpler - <a href="http://blogs.sitepoint.com/php-simple-object-iterators/">object iterators</a>.
</p>
<blockquote>
If you've been coding in PHP for a while, you may be familiar with the foreach loop. It provides an easy way to analyze every item in an array. As well as arrays, it's also possible loop through an object. If your object contains a collection of items, you can use a foreach loop to iterate over each of them. [...] Iterators is a subject which strikes fear into the heart of many developers. They sound complex and are often explained with indecipherable abstract references.
</blockquote>
<p>
To help combat this impression, he gives a bit more practical example - turning a regular array into an ArrayIterator and looping through the collection as an object instead of just a variable. This helps to keep things contained.
</p>]]></description>
      <pubDate>Thu, 28 Apr 2011 12:15:10 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Christian Schaefer's Blog: Simply iterate over XML with plain PHP using little memory and CPU]]></title>
      <guid>http://www.phpdeveloper.org/news/16023</guid>
      <link>http://www.phpdeveloper.org/news/16023</link>
      <description><![CDATA[<p>
In <a href="http://test.ical.ly/2011/03/08/simply-iterate-over-xml-with-plain-php-using-little-memory-and-cpu/">a new post</a> to his Test.ical.ly blog <i>Christian Schaefer</i> shows you how to iterate over XML in a more efficient way with the help of the <a href="http://php.net/xmlreader">XMLReader</a> and Iterator features that come with PHP.
</p>
<blockquote>
One of the things I have been working on lately was a simple XML parser. It's a simple XML structure in my case though it could be more complex without much change. My solution was a quite powerful yet simple combination of XMLReader and the Iterator interface.
</blockquote>
<p>
He includes a sample XML document similar to the one he was working with and shows how XMLReader can handle it, keeping only the currently needed information in memory at one time. His sample class (CustomXml) loads the file and defines all of the iterator methods to work with the data like "next", "prev" and "rewind".
</p>]]></description>
      <pubDate>Thu, 10 Mar 2011 08:11:31 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Kevin Schroeder's Blog: You want to do WHAT with PHP? Chapter 5]]></title>
      <guid>http://www.phpdeveloper.org/news/15074</guid>
      <link>http://www.phpdeveloper.org/news/15074</link>
      <description><![CDATA[<p>
<i>Kevin Schroeder</i> has <a href="http://www.eschrade.com/page/want-what-with-chapter-4c7fada0">the latest excerpt</a> from his book posted ("You Want to Do WHAT with PHP?") with a focus on the <a href="http://php.net/spl">SPL</a> - Standard PHP Library. He specifically takes a quick look at Iterators.
</p>
<blockquote>
If you are doing any data processing whatsoever you are using arrays.  And most likely you are doing database queries, iterating over the results and doing your algorithm-ing.  But what if you have additional functionality that you need to have integrated with your data.  You could go the traditional route and copy and paste half your application around or you could build, what we like to call structured applications.  SPL allows you to do that.
</blockquote>
<p>
In the excerpt he mentions the methods that come built in to Iterators like rewind, current and valid. There's also some sample code showing a custom iterator that works with some user data to output the information set in the constructor. You can find out more about this chapter and the rest in <a href="http://mcpressonline.stores.yahoo.net/5112.html">Kevin's book</a>.
</p>]]></description>
      <pubDate>Fri, 03 Sep 2010 11:14:58 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Matthew Weier O'Phinney's Blog: Applying FilterIterator to Directory Iteration]]></title>
      <guid>http://www.phpdeveloper.org/news/14972</guid>
      <link>http://www.phpdeveloper.org/news/14972</link>
      <description><![CDATA[<p>
New on his blog <i>Matthew Weier O'Phinney</i> has <a href="http://weierophinney.net/matthew/archives/244-Applying-FilterIterator-to-Directory-Iteration.html">this post</a> looking about using the FilterIterator (from PHP's SPL libraries) to work with (recursive) directory iteration.
</p>
<blockquote>
I'm currently doing research and prototyping for autoloading alternatives in Zend Framework 2.0. One approach I'm looking at involves creating explicit class/file maps; these tend to be much faster than using the include_path, but do require some additional setup. [...] I'm well aware of RecursiveDirectoryIterator, and planned to use that. However, I also had heard of FilterIterator, and wondered if I could tie that in somehow. In the end, I could, but the solution was non-obvious. 
</blockquote>
<p>
He starts with what he thought he should be able to do with the FilterIterator - pass in a DirectoryIterator to be able to filter them recursively. Unfortunately this only worked for the first level, so he looked else where. His solution ultimately involved passing in a RecursiveIteratorIterator instance into the DirectoryIterator that contained his RecursiveDirectoryIterator. He includes a full code example in the post showing how to locate a certain file/class recursively inside a directory.
</p>]]></description>
      <pubDate>Tue, 17 Aug 2010 10:29:38 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Sean Coates' Blog: A Case of Mistaken Iterator]]></title>
      <guid>http://www.phpdeveloper.org/news/14872</guid>
      <link>http://www.phpdeveloper.org/news/14872</link>
      <description><![CDATA[<p>
In a <a href="http://seancoates.com/blogs/a-case-of-mistaken-iterator">new post to his blog</a> today <i>Sean Coates</i> talks about some of his work with Iterators in PHP and how, despite a bad example in the manual, he solved his issue (and updated the PHP manual too).
</p>
<blockquote>
In the back end, we have models that connect to <a href="http://couchdb.apache.org/">CouchDB</a>. These models implement the <a href="http://en.wikipedia.org/wiki/Iterator">Iterator</a> pattern to allow easy traversal of a record's keys. [...] Little did I realize that this implementation is very broken. [...] Over the past few years, I've implemented many iterators in this way, using PHP's implicit array manipulation functions (reset(), current(), key(), next()). 
</blockquote>
He points out some issues with how PHP handles array index tracking and how, in the previous PHP manual example, it incorrectly checked for "false" against the current array value. His updated version doesn't have this issue. You can see it <a href="http://svn.php.net/viewvc?view=revision&revision=301637">here</a>.
</p>]]></description>
      <pubDate>Thu, 29 Jul 2010 12:48:51 -0500</pubDate>
    </item>
  </channel>
</rss>

