Get variable from $this->variable
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/804850/get-php-class-property-by-string">Get PHP class property by string</a><br>
  <a href="http://stackoverflow.com/questions/3724112/php-method-chaining">PHP method chaining?</a>  </p>
</blockquote>



<p>I've got a class where a method returns the instance it's called on. How can I access a property (whose name is stored in a variable) directly from the return value of the function? Here's what I'm trying now:</p>

<pre><code>class MyClass {
    public $variable_one;

    public function function_one() {
        $variable = 'last';
        // The problematic line: call method, access property on result
        return $this-&gt;function_two-&gt;$variable;
    }

    public function function_two($params = array()) {
        if (is_array($params)) {
            $params = http_build_query($params, NULL, '&amp;');
        }

        $this-&gt;option(CURLOPT_COOKIE, $params);
        return $this;
    }
}
</code></pre>
