How to use the database class methods in other classes?

There is a Database class to work with database. Still have a Session class for sessions. In the class session has database queries, and the queries are done through the Database class. How to make visible the Database class methods in the class Session?

Nothing but to use $GLOBALS in the designer, I figured it out. Prompt how generally to implement it?

$Database = new Database;

$Session = new Session;


And actually what I use in the constructor of the class Session:
private Database;

public function __construct()
{
$this->Database = isset($GLOBALS['Database']) ? $GLOBALS['Database'] : new Database;
}


It works, but the appropriateness of such a decision?
July 2nd 19 at 18:24
2 answers
July 2nd 19 at 18:26
I'm afraid to even ask why you have decided that $GLOBALS is better than passing a parameter to the constructor.
Urgent read all www.phptherightway.com
In particular, on the theme: www.phptherightway.com/#dependency_injection
Well, you can see something, for example: php-di.org/doc/understanding-di.html
Thanks for the reply, I will implement the transfer of the Database argument. - Eddie66 commented on July 2nd 19 at 18:29
July 2nd 19 at 18:28
class Session 
{
 private $Database;

 public function __construct(DatabaseInterface $Database)
{
 $this->Database = $Database;
}
}



interface DatabaseInterface {}



class Database implements DatabaseInterface {}
Trying to grasp the essence. :-) - Eddie66 commented on July 2nd 19 at 18:31

Find more questions by tags DatabasesPHP