abstract:下面小編就為大家?guī)?lái)一篇PHP實(shí)現(xiàn)鏈?zhǔn)讲僮鞯脑碓斀?。在一個(gè)類中有多個(gè)方法,當(dāng)你實(shí)例化這個(gè)類,并調(diào)用方法時(shí)只能一個(gè)一個(gè)調(diào)用,類似:db.php<?php class db { public function where() { //code here } public function order() { //code
下面小編就為大家?guī)?lái)一篇PHP實(shí)現(xiàn)鏈?zhǔn)讲僮鞯脑碓斀狻?/p>
在一個(gè)類中有多個(gè)方法,當(dāng)你實(shí)例化這個(gè)類,并調(diào)用方法時(shí)只能一個(gè)一個(gè)調(diào)用,類似:
db.php
<?php class 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();
如果要實(shí)現(xiàn)鏈?zhǔn)秸{(diào)用,這要在方法的結(jié)束添加return $this即可。
db.php
<?php class db { public function where() { //code here return $this; } public function order() { //code here return $this; } public function limit() { //code here return $this; } }
index.php
<?php $db = new db(); $db->where()->order()->limit();
更多關(guān)于PHP實(shí)現(xiàn)鏈?zhǔn)讲僮鞯脑碓斀庹?qǐng)關(guān)注PHP中文網(wǎng)(m.miracleart.cn)其它文章!