something missing in object by scanning directory
<p>i coded the following object in php. it was working, but after changing something in my structur the directory crawler only save the last found directory in the array.</p>

<pre><code>&lt;?php

include_once('root.php');

class crawler
{

private $pages = array();

/**
 * @param string $dir
 * @return array current_dir
 */
function found_dir($dir)
{
//         echo "Found (dir): {$dir}\n";
    // add $dir to $pages
    $parts = explode("/", $dir);
    $current = &amp;$this-&gt;pages;
    // e.g. ./content/page/sub_page/
    //  [0] =&gt; '.'
    //  [1] =&gt; 'content'
    // [-1] =&gt; ''
    for ($i = 2; $i &lt; count($parts) - 1; $i++) {
        if (!in_array('sub', $current))
            $current['sub'] = array();
        if (!in_array($parts[$i], $current['sub']))
            $current['sub'][$parts[$i]] = array('name' =&gt; $parts[$i]);
        $current = &amp;$current['sub'][$parts[$i]];
    }
    return $current;
}

/**
 * @param string $file
 */
function found_file($file)
{
//        echo "Found (file): {$file}\n";
    // move to current $dir
    $current = &amp;$this-&gt;found_dir($file);
    // add $file to $pages
    $parts = explode(".", substr($file, strrpos($file, "/") + 1));
    if (count($parts) == 1) {
        $current[$parts[0]] = file_get_contents($file);
    } else {
        if (strlen($parts[0]) == 0)
            $current[$parts[1]] = true;
        else if (!in_array($parts[0], $current))
            $current[$parts[0]] = array($parts[1] =&gt; file_get_contents($file));
        else
            $current[$parts[0]][$parts[1]] = file_get_contents($file);
    }
}

/**
 * @param string $root
 */
function read_all_files($root = '.')
{
    // vars for handling
    $directories = array();
    $last_letter = $root[strlen($root) - 1];
    $root = ($last_letter == '\\' || $last_letter == '/') ? $root : $root . DIRECTORY_SEPARATOR;
    $directories[] = $root;

    while (sizeof($directories)) {
        $dir = array_pop($directories);
        if ($handle = opendir($dir)) {
            while (false !== ($file = readdir($handle))) {
                if ($file == '.' || $file == '..') {
                    continue;
                }
                $file = $dir . $file;
                if (is_dir($file)) {
                    $directory_path = $file . DIRECTORY_SEPARATOR;
                    array_push($directories, $directory_path);

                } elseif (is_file($file))
                    $this-&gt;found_file($file);
            }
            closedir($handle);
        }
    }
}

/**
 * @return root
 */
public function generatePages()
{
    // get available files, create temp array
    $this-&gt;read_all_files('./content/');
    // print
    print_r($this-&gt;pages);
    // loop array
    return new root($this-&gt;pages);
}

}
</code></pre>

<p>i can't find the error. perhaps somebody of you see the error. thank you very much for help!</p>

<p>beste regards</p>
