php - Fatal error: Call to a member function first() on a non-object -


yes know there lot of questions topic searched , tried answers none of them helped me. that's why created question own code.

class student{     private $_db,             $_first;  public function __construct() {     $this->_db = db::getinstance(); }  public function getlast($fields = array()) {     $columns = 'admission_no, id';     $orderby = 'id';     $order = 'desc';      if(!empty($fields['columns'])){         $columns = $fields['columns'];     }      if(!empty($fields['order_by'])){         $orderby = $fields['oder_by'];     }      if(!empty($fields['order'])){         $order = $fields['order'];     }      $data = $this->_db->query("select {$columns} students order {$orderby} {$order} limit 1");      if($data->count()){         $this->_first = $data->first();         return true;     }     return false; }  public function first() {     return $this->_first; }  } 

above code of student class. , in below code calling student class, while calling student class error.

$student = new student;  $admission = $student->getlast()->first(); $admission_no = $admission->admission_no;  echo $admission_no; 

can guys can give me hints or clue. appreciated.

thank you!

$admission = $student->getlast()->first(); 

this piece of code totally bad. call method first() on result of method getlast() not on $student object. getlast() return true or false not object sure. try:

$student->getlast(); $admission = $student->first(); 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -