在一個類中有多個方法,當你實例化這個類,并調用方法時只能一個一個調用,類似:
db.php
<?phpclass db{public function where(){//code here}public function order(){//code here}public function limit(){//code here}} index.php
<?php$db = new db();$db->where();$db->order();$db->limit();
如果要實現鏈式調用,這要在方法的結束添加return $this即可。
db.php
<?phpclass db{public function where(){//code herereturn $this;}public function order(){//code herereturn $this;}public function limit(){//code herereturn $this;}} index.php
<?php$db = new db();$db->where()->order()->limit();
以上這篇PHP實現鏈式操作的原理詳解就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VeVb武林網。
新聞熱點
疑難解答
圖片精選