<?php
/**
* 父類有方法裏面用self,子類調用該方法self依然指向的是父類,父類中改self爲static
*/php
class Person{io
public function createSelf(){
return new self();
}
public function createChild(){
return new static();
}
public function eat(){
echo "Person eat";
}function
public function foo(){
self::food();
// static::food();
}class
public static function food(){
echo "Person food";
}
}方法
class Man extends Person{
public function eat(){
echo "Man eat";
}static
public function ManFun(){
echo "Man have a function";
}new
public static function food(){
echo "Man food";
}
}return
$man = new Man(); $n = $man->createChild(); // var_dump($n); $n->eat(); echo "\n"; $n->foo(); ?>