php的鏈式操作在類裏面的方法中返回的是$this,即爲當前對象;
例如:
class Database { function where($where){ echo $where . '--'; return $this; } function limit($limit){ echo $limit . '--'; return $this; } function order($order){ echo $order . '--'; return $this; } } $db = new Database; $db->where('where1')->where('where2')->limit(2)->order('order');
我想不僅僅在php中是這樣實現,在其他語言中應該也是採用這種方式來實現的(猜想);