Where am I losing my object context?
<p>One more try at this.  I've already had my previous question down voted.</p>

<p>I am loading a class through a class that is never instantiated via a static method.  The class I am loading however is supposed to be instantiated but I suspect that execution never gets that far.  There is nothing static in this class, but php keeps throwing:</p>

<pre><code>**Fatal error: Using $this when not in object context**
</code></pre>

<p>Here is the class in it's entirety:</p>

<pre><code>class Config{


    public $_config;



    public function load()
    {
        $modules = array();
        $modules = scandir(MOD);
        $n = count($modules);
        for($i=0;$i&lt;$n;$i++)
        {
            if($modules[$i]==='.'||$modules[$i]==='..'||strpos($modules[$i],'.'))
            { unset($modules[$i]); }

        }
        $modules = array_values($modules);
        $m = count($modules);

        for($i=0;$i&lt;$m;$i++)
        {
            $mod = $modules[$i];
            $this-&gt;_config[$mod] = array();// **Error thrown here.**
            $cfgfiles = scandir(MOD.DS.$mod.DS.'config');
            $num = count($cfgfiles);

            for($i=0;$i&lt;$num;$i++)
            {
                if($cfgfiles[$i]==='.'||$cfgfiles[$i]==='..')
                    { unset($cfgfiles[$i]); }
            }

            $cfgfiles = array_values($cfgfiles);
            $k = count($cfgfiles);

            for($j=0;$j&lt;$k;$j++)
            {
                include(MOD.DS.$mod.DS.'config'.DS.$cfgfiles[$j]);
                $modcfg = substr($cfgfiles[$j], 0, -4);
                $this-&gt;_config[$mod][$modcfg] = array();
                $this-&gt;_config[$mod][$modcfg] = $cfg;
            }

        } 
        return $this-&gt;_config;
    }

}
</code></pre>

<p>More information outlining my problem can be found here:</p>

<p><a href="http://stackoverflow.com/questions/11653956/using-this-when-not-in-object-context-but-supposedly-i-am">Using $this when not in object context but supposedly I am</a></p>

<p>Ok, as requested, here is the code that calls this class and yes, it is a static function.  This is what I was wondering about, but the fact that the function in the other class was static did not seem to have any effect on the loading of other classes, only this one.</p>

<pre><code>public static function init()
{
    $farray = scandir(SYS);

    for ($i=0;$i&lt;count($farray);$i++)
        { if(strpos($farray[$i],'.php'))
        {
        $item = $farray[$i];
        require (SYS.DS.$item);
        $className = substr($item, 0, -4);
        self::$_names[] = $className;
        $obj = new $className();
        self::$_objs[] = $obj;
        self::$_classes = array_combine(self::$_names, self::$_objs);
        }
    }
}


public static function getClass($class)
{
    if(isset(self::$_classes[$class]))
        { return self::$_classes[$class]; }
    else
        { return false; }
}
</code></pre>

<p>Ok, I added a <code>debug_backtrace()</code> at the line just before the <code>error($this-&gt;_config[$mod]=array())</code> and this is what I get, but I do not understand what it means.</p>

<pre><code>array(2) 
 { [0]=&gt; array(6) 
{ ["file"]=&gt; string(25) "C:\xampp\htdocs\framework\fw.php" 
["line"]=&gt; int(45) 
["function"]=&gt; string(4) "load" 
["class"]=&gt; string(6) "Config" 
["type"]=&gt; string(2) "::" 
["args"]=&gt; array(0) { } } 

[1]=&gt; array(6) 
{ ["file"]=&gt; string(26) "C:\xampp\htdocs\index.php" 
["line"]=&gt; int(31) 
["function"]=&gt; string(4) "init" 
["class"]=&gt; string(2) "Fw" 
["type"]=&gt; string(2) "::" 
["args"]=&gt; array(0) { } } }
</code></pre>

<hr>

<p>Ok, I've done everyone who responded to this question a dis-service. It turns out that I was indeed inadvertently making a static method call to Config::load in Fw::init.  Because I had made so many revisions and worked on it until I was bleary eyed I unknowingly ended up with two different version of the same class, one on my server and one in my editor. </p>

<p>I am now going off to learn how to use a source control application.</p>
