title: PHP closure function appended to stdObject and chained
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/4535330/calling-closure-assigned-to-object-property-directly">Calling closure assigned to object property directly</a>  </p>
  </blockquote>
  
  
  
  <p>If I have a class like this:</p>
  
  <pre><code>class test{
    function one(){
       $this-&gt;two()-&gt;func(); //Since $test is returned, why can I not call func()?
    }
  
    function two(){
      $test = (object) array();
      $test-&gt;func = function(){
         echo 'Does this work?';
      };
      return $test;
    }
  }
  
  $new = new test;
  $new-&gt;one(); //Expecting 'Does this work?'
  </code></pre>
  
  <p>So my question is, when I call function two from function one, function two returns the $test variable which has a closure function of func() attached to it.  Why can I not call that as a chained method?</p>
  
  <p><strong>Edit</strong>
  I just remembered that this can also be done by using $this->func->__invoke() for anyone that needs that.</p>