class Controller{
public function index(){
$tool = new Tool();
$tool->setting('123');
$tool->setting('456');
echo $tool->show();
}
}
class Tool{
public $a = ''; //這是不可行的
public function setting($data){
$this->a = $this->a.$data;
}
public function show(){
return $this->a;
}
}
$controller = new Controller();
$controller->index();
//理想結果為 123456
感謝weiclin的回覆
的確是忘了加上$this,補上後就能動了,謝謝。