class test{
public static function test(){
self::func();
static::func();
}
public static function func(){}
}可你知道self和static的区别么?
其实区别很简单,只需要写几个demo就能懂:
Demo for self:
class Car
{
public static function model(){
self::getModel();
}
protected static function getModel(){
echo "This is a car model";
}
}Car::model();
Class Taxi extends Car
{
protected static function getModel(){
echo "This is a Taxi model";
}
}Taxi::model();
得到输出
This is a car model This is a car model
可以发现,self在子类中还是会调用父类的方法
Demo for static
class Car
{
public static function model(){
static::getModel();
}
protected static function getModel(){
echo "This is a car model";
}
}
Car::model();
Class Taxi extends Car
{
protected static function getModel(){
echo "This is a Taxi model";
}
}
Taxi::model();得到输出
This is a car model This is a Taxi model