problem with PHP References
<p>I have the following PHP function</p>

<pre><code>protected function &amp;__group($ar_path, $b_create) {
    assert('is_null($ar_path) || is_array($ar_path)');
    $parent = &amp;$this-&gt;ma_config;

    if (!is_null($ar_path) &amp;&amp; (count($ar_path) &gt; 0)) {
        if ($b_create) {
            // Get with Create is necessary
            foreach ($ar_path as $group) {
                if (!array_key_exists('groups', $parent)) {
       /*MARKER*/   $parent['groups'] = array($group =&gt; array()); 
                    // Mark the File as Modified
                    $this-&gt;mb_dirty = true;
                    continue;
                }

                $parent = &amp;$parent['groups'];
                if (!array_key_exists($group, $parent)) {
                    $parent[$group] = array();
                    // Mark the File as Modified
                    $this-&gt;mb_dirty = true;
                    continue;
                }

                $parent = &amp;$parent[$group];
            }
        } else {
            // Simple Get
            foreach ($ar_path as $group) {
                $parent = array_extract_key(
                    array('groups', $group), 
                    $parent, 
                    'is_array'
                );
                if (is_null($parent)) {
                    break;
                }
            }
        }
    }
    return $parent;
}
</code></pre>

<p>The function is supposed to allow me to create 'groups' at any level (i.e. nested groups).</p>

<p>What seems to be the problem is the way PHP handles references.
When I send in something like <code>ar_path('level 1','level 2')</code>, the function should create a child group to 'level 1' if it doesn't exist.</p>

<p>Therefore given something like:</p>

<pre><code>$this-&gt;ma_config = array(
    'groups' =&gt; array(
        'level 1' =&gt; array(
            'values' =&gt; array(
                '1',
                '2'
            )
        )
    )
);
</code></pre>

<p>I should end up with something like:</p>

<pre><code>$this-&gt;ma_config = array(
    'groups' =&gt; array(
        'level 1' =&gt; array(
            'groups' =&gt; array(
                'level 2' =&gt; array()
            ),
            'values' =&gt; array(
                '1',
                '2'
            )
        )
    )
);
</code></pre>

<p>The problem is that, on my second pass through the loop, when I run line <code>/*MARKER*/</code> to create the second level (i.e. which should have resulted in <code>$this-&gt;ma_config['groups']['level 1]['groups']['level 2'] = array()</code>) it destroys the 'level 1' instead (it seems, from the debugger, that PHP ends up doing this instead <code>$this-&gt;ma_config['groups']['level 1] = array()</code>)</p>

<p>Why?</p>
