I have the following problem - lets say I have a class named Database
class Database
{
public function insert(...)
{
//insert something in the database
}
}
And I have a class named User
class User
{
public function register(..)
{
//validate the user , and insert him
//here i need to call insert() function from Database class
}
}
Is there a simple way in which I can call the insert method inside the User class?
dependency injection- perhaps might be of interest php-di.org/doc/understanding-di.html and / or stackoverflow.com/questions/130794/what-is-dependency-injectionDatabaseclass need to be instanciated? Why not make it static?static public function insert(), then inregister(), useDatabase::insert(...).