PHP: __set function behaviour different each time
<p>This manages to create a new property on the object.  But, can someone explain, with supporting links, why <code>setAttrib</code> behaves in two different ways?  Why doesn't it cause a... wait for it... stack overflow!!??</p>

<pre><code>class Test
{
  public function setAttrib( $key, $value ) {
    echo "setAttrib\n";

    // first time: calls $this-&gt;__set($key, $value)
    // second time: just sets a public property (but, when exactly was it created?)
    $this-&gt;$key = $value;
  }

  public function __set( $key, $value ) {
    echo "__set\n";
    $this-&gt;setAttrib($key, $value);
  }
}

$test = new Test();
$test-&gt;setAttrib('hey', 'It works');
var_dump($test);
</code></pre>

<p>produces...</p>

<pre><code>setAttrib
__set
setAttrib
object(Test)#1 (1) {
  ["hey"]=&gt;
  string(8) "It works"
}
</code></pre>

<p>Edit: I'm not looking for an alternative.  <em>I'm looking for the reason why this works.</em></p>
