У меня есть 2 функции в классе item-> display_item()
и get_category_item()
class db{ protected $db_host; protected $db_name; protected $db_user_name; protected $db_pass; protected $conn; public function __construct() { $this->db_host="localhost"; $this->db_name="bs"; $this->db_user_name="root"; $this->db_pass=""; try { $this->conn = new PDO("mysql:host=$this->db_host;dbname=$this->db_name", $this->db_user_name, $this->db_pass); $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch(PDOException $e) { echo $sql . "<br>" . $e->getMessage(); } } } require "../../includes/db.php"; class item extends db{ public function display_item($uid){ $this->user_uid=$uid; try{ $sql="SELECT * FROM item where uid='$this->user_uid'"; $statement=$this->conn->query($sql); while($row=$statement->fetch()){ $this->display_item[$row['iid']]=[$row['item_id'],$row['item_name'],$row['item_price'],$row['item_quantity']]; } } catch(PDOException $e){ ... } } public function get_category_item($uid,$iid){ $this->user_uid=$uid; $this->item_iid=$iid; try{ $sql=" SELECT category_item.iid,category_item.uid,item_category.item_category_name,item_category.cid FROM category_item JOIN item_category ON item_category.uid=category_item.uid and item_category.cid=category_item.cid where item_category.uid='$this->user_uid' and category_item.iid='$this->item_iid'; "; $statement=$this->conn->query($sql); while($row=$statement->fetch()){ $this->get_category_item_name[]=$row['item_category_name']; } } catch(PDOException $e){ ... } } }
вclass db{ protected $db_host; protected $db_name; protected $db_user_name; protected $db_pass; protected $conn; public function __construct() { $this->db_host="localhost"; $this->db_name="bs"; $this->db_user_name="root"; $this->db_pass=""; try { $this->conn = new PDO("mysql:host=$this->db_host;dbname=$this->db_name", $this->db_user_name, $this->db_pass); $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch(PDOException $e) { echo $sql . "<br>" . $e->getMessage(); } } } require "../../includes/db.php"; class item extends db{ public function display_item($uid){ $this->user_uid=$uid; try{ $sql="SELECT * FROM item where uid='$this->user_uid'"; $statement=$this->conn->query($sql); while($row=$statement->fetch()){ $this->display_item[$row['iid']]=[$row['item_id'],$row['item_name'],$row['item_price'],$row['item_quantity']]; } } catch(PDOException $e){ ... } } public function get_category_item($uid,$iid){ $this->user_uid=$uid; $this->item_iid=$iid; try{ $sql=" SELECT category_item.iid,category_item.uid,item_category.item_category_name,item_category.cid FROM category_item JOIN item_category ON item_category.uid=category_item.uid and item_category.cid=category_item.cid where item_category.uid='$this->user_uid' and category_item.iid='$this->item_iid'; "; $statement=$this->conn->query($sql); while($row=$statement->fetch()){ $this->get_category_item_name[]=$row['item_category_name']; } } catch(PDOException $e){ ... } } }
вclass db{ protected $db_host; protected $db_name; protected $db_user_name; protected $db_pass; protected $conn; public function __construct() { $this->db_host="localhost"; $this->db_name="bs"; $this->db_user_name="root"; $this->db_pass=""; try { $this->conn = new PDO("mysql:host=$this->db_host;dbname=$this->db_name", $this->db_user_name, $this->db_pass); $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); } catch(PDOException $e) { echo $sql . "<br>" . $e->getMessage(); } } } require "../../includes/db.php"; class item extends db{ public function display_item($uid){ $this->user_uid=$uid; try{ $sql="SELECT * FROM item where uid='$this->user_uid'"; $statement=$this->conn->query($sql); while($row=$statement->fetch()){ $this->display_item[$row['iid']]=[$row['item_id'],$row['item_name'],$row['item_price'],$row['item_quantity']]; } } catch(PDOException $e){ ... } } public function get_category_item($uid,$iid){ $this->user_uid=$uid; $this->item_iid=$iid; try{ $sql=" SELECT category_item.iid,category_item.uid,item_category.item_category_name,item_category.cid FROM category_item JOIN item_category ON item_category.uid=category_item.uid and item_category.cid=category_item.cid where item_category.uid='$this->user_uid' and category_item.iid='$this->item_iid'; "; $statement=$this->conn->query($sql); while($row=$statement->fetch()){ $this->get_category_item_name[]=$row['item_category_name']; } } catch(PDOException $e){ ... } } }
когда я их называю один за другим, он отлично работает для обеих функций. Однако, если я назову их обоими в одном файле, я получил
Неустранимая ошибка: вызов функции-функции-члена () на null
$display=new item(); $display->display_item(1); $display->get_category_item(1,383);
Другими словами, я могу назвать только один из них, но не оба в одном файле. Могу ли я узнать, какая часть пошла не так?