I have a database class which contains the following method:
class Database {
// Fetch array - one column
public function fetch_array_column_ex(){
$query = $this->execute();
return $query->fetchAll(PDO::FETCH_COLUMN, 0);
} // End fetch_array() function
}
Fine.
I then extended the Database class like so:
class Node extends Database {
public function fetch_array_column_user($user_id) {
$STH = $this->connection->prepare("SELECT username FROM user WHERE id = :user_id" );
$STH->bindParam(':user_id', $user_id, PDO::PARAM_INT);
return $STH;
}
}// End function fetch_array_column_user()
Instead of retuning $STH I want to call the Database method fetch_array_column_ex() but I’m getting confused about how…
class A
{
public function add($a, $b)
{
return $a + $b;
}
}
class B extends A
{
public function subtract($a, $b)
{
return $this->add($a, -1*$b);
}
}
$b = new B();
echo $b->subtract(2, 1);
Indeed you can, but take care that if you also define the function ‘add’ in class B (so class A had a function ‘add’ and class B has a function ‘add’ that overrides A::add) $this->add will call B::add, and parent::add will call A::add