PHP implementation of chain operation principle details, php Chain Principle details
There are multiple methods in a class. When you instantiate this class and call methods, you can only call them one by one. For example:
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 ();
To implement a chained call, add return $ this at the end of the method.
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 ();
The above PHP implementation of the chain operation principle is a small series to share with you all of the content, I hope to give you a reference, but also hope you can support a lot of help house.