class fatherController{ public $my_static = 'foo'; public function _initialize(){ } public function cuid(){ echo '父类的index()方法'; } }
class Test1Controller extends fatherController{ public function cire(){ echo parent::$my_static; } }
发现一个问题,子类的parent:: 只能调用父类的方法,不能调用父类声明的变量,否则 会报错,如果要调用 public $my_static = 'foo'; 改为
public static $my_static = 'foo';
class Test1Controller extends fatherController{ public function cire(){ echo '路人甲'; } public function test() { echo self::cire(); } }self:: 调用本类中的方法,不管是静态方法还是非静态的方法都可以调用,还可以调用父类中的方法;parent::大致相同