PHP self vs static
10 Sep 2018self
class Animal
{
public static function model(){
self::getModel();
}
protected static function getModel(){
echo "This is a animal model";
}
}
Animal::model();
Class Dog extends Animal
{
protected static function getModel(){
echo "This is a Dog model";
}
}
Dog::model();
Output
This is a animal model
This is a animal model
static
class Animal
{
public static function model(){
static::getModel();
}
protected static function getModel(){
echo "This is a animal model";
}
}
Animal::model();
Class Dog extends Animal
{
protected static function getModel(){
echo "This is a Dog model";
}
}
Dog::model();
Output
This is a animal model
This is a Dog model
https://segmentfault.com/a/1190000005060322