Class A { function A () {//constructor include ( 'db.php' ); $this->db = new DB();//responsible for database operations $this->C = new C();//when instanciated, should echo those records } function get_records () {//returns a number return $this->db->RecordCount ( 'SELECT * FROM bla bla' ); } } $class = new A(); Class C { global $class; function C () {//constructor echo $class->get_records (); } } PHP: When I do this I het an error that $class is not an object (call to a member function on a non object). Any idea why?
that is a mess i dont think you understand inheritance etc. to be able to use methods from class A you need class C to extend Class A and why are you making an instance of the supposed child class C in the parent class A?
Class A { function A () {//constructor include ( 'db.php' ); $this->db = new DB();//responsible for database operations } function get_records () {//returns a number return $this->db->RecordCount ( 'SELECT * FROM bla bla' ); } } Class C extends A{ global $class; function C () {//constructor echo $class->get_records (); } } $class = new C(); PHP: this will work or at least it should