On Tue, Jan 26, 2010 at 1:25 PM, Christoph Boget <cbo...@hotmail.com> wrote:

> >
> > def not on DirectorIterator afaik, and furthermore, i dont think thats
> > supported at the shell / filesystem level even.
>
>
> Well if the Iterator has the whole of the collection in order to be able to
> iterate over it, I would think that it should be able to return the size of
> that collection... :(
>

right but the collection is built during iteration.  one thing you could do
if you wanted it to *appear* as though the count was there at construction
is to subclass and iterate once in the constructor.

something like this:

<?php
class SmartDirectoryIterator extends DirectoryIterator implements Countable
{
  private $_iCount = 0;

  public function __construct($sPath)
  {
    parent::__construct($sPath);
    foreach($this as $oFile)
      if($oFile->isFile())
        $this->_iCount++;
  }

  public function count()
  {
    return $this->_iCount;
  }
?>

-nathan

Reply via email to