class hydra {
var $dbcon;
function __construct($ezSQL){
$this -> dbcon=$ezSQL;
}
}
class user extends hydra{
function foo(){
echo "bar is: ".$this->dbcon;
}
}
I then call:
$hydra = new hydra($ezSQL);
However, at this point I get the following error:
Fatal error: Cannot instantiate abstract class hydra
How do set up a class that will inherit all of it’s children’s functions so I can do something like this:
$hydra = new hydra("foobar");
$hydra -> foo();
output:
bar is: foobar
You can not get children’s functionality into parent. Just think, does Mom gets her look from her daughter? No. Its the child who inherits from parent.
The code you have given does not throw any error. But from the error It seems hydra is an abstract class. And as you want to call the childrens method as hydra you should have that method as abstract.
Now you can instantiate
userbut call thefoo()method ashydra. Its help full in Type hinting.Here the function
dofoosees$has ahydrainstance.