Which one is the better way of using an object?
class A
{
$db = new database;
...
...
function connect_db()
{
this->db->connect_db();
}
}
or
class A extends database
{
...
...
function connect_db()
{
this->connect_db();
}
}
The first one instanciates a database object and use it in the method to connect to db so A can update/delete/insert data.
The second one extends the database class so class A inherits all from the parent class, database.
The only different I can see is that when you extend a class with another, then the extended one can do much more flexible things and you can also instanciate as many as objects you want within the class (oppose to extend multiple classes.)