An object that calls a method after a method is executed. It first returns the first select () method and then executes the second from () method (), do you want to execute the following method? An object that is called after a method
How is the process executed? First, return the first select () method, then execute the second from () method, and then execute the following method?
Reply content:
An object that is called after a method
How is the process executed? First, return the first select () method, then execute the second from () method, and then execute the following method?
In fact, it is very simple. The method is to operate on an object attribute. In the end, all the results are returned. You can use this chained method. A simple example is like this:
sql .= $str; return $this; } public function from( $str = "" ) { $this->sql .= $str; return $this; } public function __toString() { return $this->sql; }}$db = new database();echo $db->select("abc")->from("def");
Https://github.com/typecho/typecho/blob/master/var/Typecho/Db/Query.php#L423
Look at this.
What you should say is a chain operation. The statements written in the question are just a simple query statement and must be executed.$db->query()
Result set, similar to this$db->query($db->select()->from()->where())
. In the preceding constructor statement, each method returns the object itself.return $this
So you can continue to execute the following method.
Actually, the object of the current operation is returned,$this
In this way, you can implement chained operations!
The @ override example is very vivid. To put it bluntly, the function continuously returns its own reference, and then the function continuously performs operations on its own members.
If you have doubts about chain operations, you can look at this, about db api introduction http://www.typechodev.com/index.php/archives/17/