Accessing a class member variable of type Array using __get or similar
<p>Previously a class which I'm now rebuilding had a member variable <code>$settings</code> which was an array of settings, strangely enough.</p>

<pre><code>class MyClass {
    public $settings = array();

    public function __construct() {
        if( empty( $this-&gt;settings ) ) {
            $this-&gt;settings = require( 'settings.php' ); // e.g. return array('setting1'=&gt;4);
        }
    }
}
</code></pre>

<p>These settings were accessed by <code>$object-&gt;settings['keyname'];</code></p>

<p>The means by which these keys are accessed has been moved into a method now. However, the application itself is riddled with calls to <code>$object-&gt;settings['keyname']</code>. I was wondering is there a way which I can catch any calls to the <code>$settings</code> member variable and return it using the new function.</p>

<p>I've looked at <code>__get($name)</code> but <code>$name</code> only contains <code>settings</code> rather than the array key which I need. What I'd need to pass would be the keyname to the my <code>$object-&gt;get()</code> method.</p>

<p>The reason I want to do this is so that I can trigger errors in a log file showing me where the deprecated calls to <code>$object-&gt;settings[]</code> are without breaking the application. Obviously setting $setting to private would give me lots of fatal errors and I could work through but there are multiple developers working on this codebase which I'd prefer not to break. If I could implement this as a temporary solution it'd help.</p>

<p>I realise there are repositories etc which we could use so that I could work on it separately and check it in afterwards but I'm looking for a quick, temporary solution as we're porting our codebase to Git soonish.</p>
