PHP Method chaining Confusion

前端 未结 4 1858
情话喂你
情话喂你 2021-01-27 09:04

i have been lately introduced to method chaining, and am not sure if what I\'m doing here is illegal, or I\'m doing it wrong. I have a database Class like:

    c         


        
4条回答
  •  半阙折子戏
    2021-01-27 09:21

    If you want to using method chaining, what you should do is return $this.

    public function query($query)
    {
        $this->last_query = $query;
        $this->resultset = mysql_query($query, $this->connection);
        return $this;
    }
    

    Then you can do this:

    $db->query("SELECT * FROM users WHERE name='JimmyP'")->fetchObject();
    

提交回复
热议问题