<?phpclassPerson{public$name='bob';publicstatic$age=22;//static 修饰的是静态属性public$self=null;publicfunctionintro(){echo'My name is '.$this->name.'<br>';//My name is bob/*
echo $this->age;
报错 静态属性必须使用 类名(self)::静态属性 来调用
报错 静态方法必须使用 类名(self)::静态方法 来调用
*/echo'My age is '. self::$age.'<br>';//My age is 22echo'My age is '. self::getAge().'<br>';//My age is 22echo'My age is '.$this->getAge().'<br>';//My age is 22$this->self=newself();//此处相当于 new Person();}publicstaticfunctiongetAge(){return self::$age;}}$cc=newPerson();$cc->intro();