Confused about class extend syntax

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…

I’m not exactly sure what you want to do, but if you have a class B that extends class A you can have a class B call functions of A by using parent::


class A 
{
   public function add($a, $b)
   {
        return $a + $b;
   }
}

class B extends A
{
    public function subtract($a, $b)
    {
        return parent::add($a, -1*$b);
    }
}


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);

you can use the $this-> dereference operator too

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 :slight_smile: