<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Lies! Darn Lies!</title>
	<atom:link href="http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/</link>
	<description>News, opinion, and fresh thinking for web developers and designers. The official podcast of sitepoint.com.</description>
	<lastBuildDate>Mon, 23 Nov 2009 01:39:24 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ren</title>
		<link>http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/comment-page-1/#comment-1125</link>
		<dc:creator>Ren</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">890741415#comment-1125</guid>
		<description>&lt;p&gt;I&#039;d go for the shortest method&lt;/p&gt;

&lt;code lang=&quot;php&quot;&gt;
class FileFilterIterator extends FilterIterator
{
	function accept() { return $this-&gt;current()-&gt;isFile(); }
}
$Reader = new FileFilterIterator(new DirectoryIterator(&#039;./&#039;));

// Loop through the files in the directory ?!?
foreach ( $Reader as $Item ) {
    echo $Item.&#039;&lt;br&gt;&#039;;&lt;/code&gt;&lt;p&gt;As a side note, been wondering why an abstract OuterIterator class wasn&#039;t created in spl.&lt;/p&gt;

&lt;code lang=&quot;php&quot;&gt;
abstract class OuterIterator implements Iterator
{
	protected $iterator;

	function __construct(Iterator $iterator) { $this-&gt;iterator = $iterator; }
	function getInnerIterator() { return $this-&gt;iterator; }
	function valid() { return $this-&gt;iterator-&gt;valid(); }
	function key() { return $this-&gt;iterator-&gt;key(); }
	function current() { return $this-&gt;iterator-&gt;current(); }
	function next() { return $this-&gt;iterator-&gt;next(); }
	function rewind() { return $this-&gt;iterator-&gt;rewind(); }
}&lt;/code&gt;&lt;p&gt;which then iterators like FilterIterator would have been subclasses of. &lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>I&#8217;d go for the shortest method</p>
<p><code lang="php">
class FileFilterIterator extends FilterIterator
{
	function accept() { return $this->current()->isFile(); }
}
$Reader = new FileFilterIterator(new DirectoryIterator('./'));

// Loop through the files in the directory ?!?
foreach ( $Reader as $Item ) {
    echo $Item.'<br />';</code>
</p><p>As a side note, been wondering why an abstract OuterIterator class wasn&#8217;t created in spl.</p>
<p><code lang="php">
abstract class OuterIterator implements Iterator
{
	protected $iterator;

	function __construct(Iterator $iterator) { $this->iterator = $iterator; }
	function getInnerIterator() { return $this->iterator; }
	function valid() { return $this->iterator->valid(); }
	function key() { return $this->iterator->key(); }
	function current() { return $this->iterator->current(); }
	function next() { return $this->iterator->next(); }
	function rewind() { return $this->iterator->rewind(); }
}</code>
</p><p>which then iterators like FilterIterator would have been subclasses of. </p>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/comment-page-1/#comment-1126</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">890741415#comment-1126</guid>
		<description>&lt;p&gt;Re the original title - to keep life simple have changed it; not interested in the discussion that surrounds it and this is the shortest path &lt;i&gt;this&lt;/i&gt; time.&lt;/p&gt;

&lt;p&gt;Cant guarantee Ill do the same in future - to me, as a European, there was nothing offensive about the title - didnt even occur to me. If I start thinking about every possible culture I might offend, nothing would get written.&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;
As a side note, been wondering why an abstract OuterIterator class wasn&#039;t created in spl.&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;Thats an interesting question - guess we&#039;d need Marcuss input on that. Talking to him and studying the design I&#039;m very sure he had clear ideas in building the SPL iterators; the problem is I doubt he&#039;s going to get time to explain all the decisions that influenced the design, which would help alot.&lt;/p&gt;

&lt;p&gt;Perhaps you could propose it to him, with a use case?&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Re the original title &#8211; to keep life simple have changed it; not interested in the discussion that surrounds it and this is the shortest path <i>this</i> time.</p>
<p>Cant guarantee Ill do the same in future &#8211; to me, as a European, there was nothing offensive about the title &#8211; didnt even occur to me. If I start thinking about every possible culture I might offend, nothing would get written.</p>
<p>
<blockquote>
<p>
As a side note, been wondering why an abstract OuterIterator class wasn&#8217;t created in spl.
</p>
</blockquote>
</p><p>Thats an interesting question &#8211; guess we&#8217;d need Marcuss input on that. Talking to him and studying the design I&#8217;m very sure he had clear ideas in building the SPL iterators; the problem is I doubt he&#8217;s going to get time to explain all the decisions that influenced the design, which would help alot.</p>
<p>Perhaps you could propose it to him, with a use case?</p>]]></content:encoded>
	</item>
	<item>
		<title>By: M36Teen</title>
		<link>http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/comment-page-1/#comment-1127</link>
		<dc:creator>M36Teen</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">890741415#comment-1127</guid>
		<description>&lt;p&gt;Thanks Harry, keep up the PHP stuff, I&#039;ve learned a LOT from you! :-) &lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Thanks Harry, keep up the PHP stuff, I&#8217;ve learned a LOT from you! :-) </p>]]></content:encoded>
	</item>
	<item>
		<title>By: beatybeaty</title>
		<link>http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/comment-page-1/#comment-1128</link>
		<dc:creator>beatybeaty</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">890741415#comment-1128</guid>
		<description>&lt;p&gt;I too, would like to thank you, Harry.  Keep up the great work.  I&#039;ve learned a lot from you as well, including your books. (a *damn* lot) ;) ;)&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>I too, would like to thank you, Harry.  Keep up the great work.  I&#8217;ve learned a lot from you as well, including your books. (a *damn* lot) ;) ;)</p>]]></content:encoded>
	</item>
	<item>
		<title>By: spags</title>
		<link>http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/comment-page-1/#comment-1129</link>
		<dc:creator>spags</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">890741415#comment-1129</guid>
		<description>&lt;p&gt;Love your postings Harry! thanks, great job&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Love your postings Harry! thanks, great job</p>]]></content:encoded>
	</item>
	<item>
		<title>By: HarryF</title>
		<link>http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/comment-page-1/#comment-1130</link>
		<dc:creator>HarryF</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">890741415#comment-1130</guid>
		<description>&lt;p&gt;Ren - message from Marcus which I think was meant to endup here;&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;br /&gt;
Your idea is not bad but you lost the subdirs. You need to use&lt;br /&gt;
RecursiveDirectoryIterator instead of DirectoryIterator. Then you&lt;br /&gt;
need to iterate that with RecursiveIteratorIterator and that with&lt;br /&gt;
a filter iterator. The last being something like the opposite of&lt;br /&gt;
ParentIterator or one that uses your accept().&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;The outeriterator is an idea both Andi and me had. However it got&lt;br /&gt;
lost somewhen because i didn&#039;t fint it to important and i would&lt;br /&gt;
not allow access to the inner iterator by property. Instead i&lt;br /&gt;
would make that a private one and provide a function based&lt;br /&gt;
access. Also it doesn&#039;t need to be abstract in your case but i&lt;br /&gt;
want that so i can still have c implementations. As a consequence&lt;br /&gt;
i&#039;d do it in an Interface. Putting those ideas together gives teh&lt;br /&gt;
following:&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;interface OuterIterator extends Iterator&lt;br /&gt;
{&lt;br /&gt;
    abstract function getInnerIterator();&lt;br /&gt;
}&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

&lt;p&gt;&lt;blockquote&gt;&lt;p&gt;and then maybe have a class IteratorIterator like your one which&lt;br /&gt;
implements OuterIterator :-)&lt;br /&gt;
&lt;/p&gt;&lt;/blockquote&gt;&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>Ren &#8211; message from Marcus which I think was meant to endup here;</p>
<p>
<blockquote>
<p>
Your idea is not bad but you lost the subdirs. You need to use<br />
RecursiveDirectoryIterator instead of DirectoryIterator. Then you<br />
need to iterate that with RecursiveIteratorIterator and that with<br />
a filter iterator. The last being something like the opposite of<br />
ParentIterator or one that uses your accept().</p>
</blockquote>
</p><p>
<blockquote>
<p>The outeriterator is an idea both Andi and me had. However it got<br />
lost somewhen because i didn&#8217;t fint it to important and i would<br />
not allow access to the inner iterator by property. Instead i<br />
would make that a private one and provide a function based<br />
access. Also it doesn&#8217;t need to be abstract in your case but i<br />
want that so i can still have c implementations. As a consequence<br />
i&#8217;d do it in an Interface. Putting those ideas together gives teh<br />
following:</p>
</blockquote>
</p><p>
<blockquote>
<p>interface OuterIterator extends Iterator<br />
{<br />
    abstract function getInnerIterator();<br />
}</p>
</blockquote>
</p><p>
<blockquote>
<p>and then maybe have a class IteratorIterator like your one which<br />
implements OuterIterator :-)
</p>
</blockquote></p>]]></content:encoded>
	</item>
	<item>
		<title>By: Ren</title>
		<link>http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/comment-page-1/#comment-1131</link>
		<dc:creator>Ren</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">890741415#comment-1131</guid>
		<description>&lt;p&gt;&lt;br /&gt;
Ah yes, I didnt intend for getInnerIterator to be public. &lt;/p&gt;

&lt;p&gt;I&#039;m finding the general class helpful thou, especially when mapping either key() or current() return values to something else.&lt;/p&gt;

</description>
		<content:encoded><![CDATA[<p>
Ah yes, I didnt intend for getInnerIterator to be public. </p>
<p>I&#8217;m finding the general class helpful thou, especially when mapping either key() or current() return values to something else.</p>]]></content:encoded>
	</item>
	<item>
		<title>By: Alexios Fakos</title>
		<link>http://www.sitepoint.com/blogs/2004/09/21/lies-darn-lies/comment-page-1/#comment-1132</link>
		<dc:creator>Alexios Fakos</dc:creator>
		<pubDate>Tue, 30 Nov 1999 00:00:00 +0000</pubDate>
		<guid isPermaLink="false">890741415#comment-1132</guid>
		<description>&lt;p&gt;How about that?:)&lt;/p&gt;

&lt;code&gt;
//set_time_limit(10);

class DirectoryReader extends FilterIterator {

    protected $iter;

    function __construct($path) {

        $this-&gt;iter = new RecursiveIteratorIterator (
                          new RecursiveDirectoryIterator($path)
                      );
        parent::__construct( $this-&gt;iter );
    }

    function accept() {
        return $this-&gt;iter-&gt;getSubIterator()-&gt;isFile();
    }
}

$path = dirname(__FILE__);

foreach(new DirectoryReader($path) as $file) {
    echo $file-&gt;getPath(), &#039; --&gt; &#039;, $file-&gt;getFilename(), &quot;\n&quot;;
    /*
    or invoke __toString()...
    echo $file, &quot;\n&quot;;
    */
}&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>How about that?:)</p>
<code>
//set_time_limit(10);

class DirectoryReader extends FilterIterator {

    protected $iter;

    function __construct($path) {

        $this->iter = new RecursiveIteratorIterator (
                          new RecursiveDirectoryIterator($path)
                      );
        parent::__construct( $this->iter );
    }

    function accept() {
        return $this->iter->getSubIterator()->isFile();
    }
}

$path = dirname(__FILE__);

foreach(new DirectoryReader($path) as $file) {
    echo $file->getPath(), ' --> ', $file->getFilename(), "\n";
    /*
    or invoke __toString()...
    echo $file, "\n";
    */
}</code>]]></content:encoded>
	</item>
</channel>
</rss>
