《PHP教程:PHP實現鏈式操作的原理詳解》要點:
本文介紹了PHP教程:PHP實現鏈式操作的原理詳解,希望對您有用。如果有疑問,可以聯系我們。
PHP實戰在一個類中有多個方法,當你實例化這個類,并調用方法時只能一個一個調用,類似:
PHP實戰db.php
PHP實戰
<?php
class db
{
public function where()
{
//code here
}
public function order()
{
//code here
}
public function limit()
{
//code here
}
}
PHP實戰index.php
PHP實戰
<?php
$db = new db();
$db->where();
$db->order();
$db->limit();
PHP實戰如果要實現鏈式調用,這要在方法的結束添加return $this即可.
PHP實戰db.php
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;
}
}
PHP實戰index.php
PHP實戰
<?php
$db = new db();
$db->where()->order()->limit();
PHP實戰以上這篇PHP實現鏈式操作的原理詳解就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持維易PHP.
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/3803.html