php中子类如何调用父类的静态方法

来自:互联网
时间:2020-09-29
阅读:

子类内部访问父类静态成员属性或方法

parent::method()/self::method()

注意:$this->staticProperty(父类的静态属性不可以通过$this(子类实例)来访问,会报错:

:PHP Strict Standards: Accessing static property Person::$country as non static in,PHP Notice: Undefined property: )

子类外部访问

子类名::method()

子类实例->method() (静态方法也可以通过普通对象的方式访问)

注意:子类实例->staticProperty(父类的静态属性不可以通过子类实例来访问,会报错:

:PHP Strict Standards: Accessing static property Person::$country as non static in,PHP Notice: Undefined property: )
返回顶部
顶部