Using $this when not in object context
<p>maybe it is to early in the morning or I'm totally blind, but why to I get a 'Fatal error: Using $this when not in object context' in the following code. There is nothing static in there.</p>

<p>The class:</p>

<pre><code>&lt;?php

class Property
{

    /**
     * @var string[]
     */
    private $values;

    public function __contruct($file)
    {
        $this-&gt;values = parse_ini_file($file, false);
    }

    /**
     * @return string
     */
    public function get($key, $default = null)
    {
        if (key_exists($key, $this-&gt;values)) { //&lt;-- error
            return $this-&gt;values[$key];
        }
        return $default;
    }
}
</code></pre>

<p>The test:</p>

<pre><code>&lt;?php

class PropertyTest extends Test
{

    public function testGet()
    {
        $prop = new Property($this-&gt;getResource('test.properties'));
        $this-&gt;assertEquals('foo', $prop-&gt;get('test.entry', 'xyz')); 
        $this-&gt;assertEquals('bar', $prop-&gt;get('test.entry2', 'xyz'));
        $this-&gt;assertEquals('xyz', $prop-&gt;get('test.entry3', 'xyz'));
        $this-&gt;assertEquals(null, $prop-&gt;get('test.entry3'));
    }
}
</code></pre>

<h1>Edit</h1>

<p><strike>The error comments indicating the trace. The error occures while running the PropertyTest->testGet() on the the first $prop->get() caused by the first line of the Property->get() method.</strike></p>

<h1>Solution</h1>

<p>Beside the typo xdazz found, and the deprecation Phil pointed at, user985935 was right. :)</p>

<p>To make it short, my class loader used the static get and the phpUnit error mislead my investigations and my information I offer you for finding my problem. Sorry.</p>
