Possible Duplicate:
Get PHP class property by string
PHP method chaining?
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:
class MyClass {
public $variable_one;
public function function_one() {
$variable = 'last';
// The problematic line: call method, access property on result
return $this->function_two->$variable;
}
public function function_two($params = array()) {
if (is_array($params)) {
$params = http_build_query($params, NULL, '&');
}
$this->option(CURLOPT_COOKIE, $params);
return $this;
}
}