Finally installed php7. Before that, everything worked fine on php5.6, even without replacing mysql with mysqli. But I installed php7 - the site fell out of error, I quickly rewrote all the calls to working with the database, but an incomprehensible error appeared ...

php fatal error uncaught error using $this when not in object context 

I will give the code where it is called, although in other areas the work with the base as the same goes. and it comes to this place, and here he does not like something ...

 class Site extends Widget { function Site(&$parent) { Widget::Widget($parent); $this->main = new Widget($this); $this->categories = Storefront::get_categories(); ... } ... } class Storefront extends Widget { function Storefront(&$parent) { Widget::Widget($parent); // там появляется указатель на db // this->db = &parent->db, так как база инициализируеться в widget ... } // Функция возвращает категории товаров, и их подкатегории function get_categories($parent = 0) { $r = $this->db->query($query); // * вот на этой строчке $tree = array(); while ($category = $this->db->fetchObject($r)) { // .... тут я работаю с категориями, 

I will give the code of this function query now

 # Execute the query or queries array public function query($q) { if ($this->link) { $start = microtime(true); $this->res_id = mysqli_query($this->link,$q); } else { $this->error_msg = "Could not execute query to $this->db_name database, wrong database link"; return 0; } if (!$this->res_id && $this->exception_on_error) { trigger_error("Could not execute query to $this->db_name database, wrong result id", E_USER_ERROR); return 0; } return $this->res_id; } 

I call this: Site is the heir of the widget (it contains initialization of the class bd) In site, the widget constructor is called (there is a link to the database) in the widget class there is this-> db = new db.class in it all the functions for working with the base. When we use db in the site, this-> db = & parent-> db; and I appeal to the database already through this-db ... In the site we call another class responsible for displaying the categories of the store, it is also the heir of the widget .. I hope it is clear)

  • But is that line you have in the method of one of the classes or outside of any class? - Visman
  • right now I will add in the question - Alex Lizenberg
  • Better show the code of the file in which $r = $this->db->query($query); ........ Maybe you do it in the static method ..... and also show how you call this very method ..... maybe you call the non-static method as static. those. foobar::foobarfunc(); you need foobar->foobarfunc(); - Alexey Shimansky
  • the code is big. I mean, I create a new class as an inheritor of the main class and in the constructor I make a class there Storefront extends Widget {function Storefront (& $ parent) {Widget :: Widget ($ parent); ....... I make it so that he inherits all the parameters of the parent through & - Alex Lizenberg
  • 2
    @ AlexLizenberg you call Storefront :: get_categories (), i.e. You do not have a Storefront object. Consequently, you cannot access it at $ this-> - cheops

0