My script has 3 classes (that are relevant to this discussion): DB, User and Validate. They are all in independent files and loaded automatically, when required, by an autoloader.
Both the User class and the Validate class have a private variable $_db which is instantiated by their class constructor: $this->_db = DB::getInstance();
At the top of the script I declare new instances: $user = new User(); and $validate = new Validate();
I then call a method in $user: $found = $user->findInUsers ( .... )
From within the findInUsers method I then want to call the query method in the DB class. My problem is that I can't find a way to do this that works.
I have tried $this->_db->query( ... ), $_db->query( ... ), but neither works.
The error messages I am getting are:
An error occurred in script '/srv/http/classes/User.php' on line 42: Undefined variable $_db
Uncaught Error: Call to a member function query() on null in /srv/http/classes/User.php:42
Any pointers as to what I am doing wrong, or what I should be doing, would be most welcome.