重複の可能性:文字列PHP メソッド チェーン
で PHP クラス プロパティを取得しますか?
メソッドが呼び出されたインスタンスを返すクラスがあります。関数の戻り値からプロパティ (名前が変数に格納されている) に直接アクセスするにはどうすればよいですか? これが私が今試していることです:
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;
}
}