How to access functions in extended classes efficiently?
- by nischayn22
In PHP I have classes as below
class Animal {
//some vars
public function printname(){
echo $this->name;
}
}
class AnimalMySql extends Animal {
static public function getTableFields(){
return array();
}
}
class AnimalPostgreSql extends Animal {
static public function getTableFields(){
return array();
}
}
Now I have an object $lion = new Animal(); and I want to do
if($store == mysql)
//getTableFields from class AnimalMySql
else
//getTableFields form class AnimalPostgreSql
I am new to OOP and not sure what is the best way to call the method from the specific class
P.S. Please leave a note with the answer to explain the efficiency of the approach