PHP Method chaining Confusion

前端 未结 4 1805
情话喂你
情话喂你 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:10

    In query(), you need to return $this otherwise there's nothing to chain it with when the function returns

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

提交回复
热议问题