Home > Backend Development > PHP Tutorial > php 子类如何访问父类的静态方法

php 子类如何访问父类的静态方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 13:42:40
Original
1784 people have browsed it

1.子类内部访问父类静态成员属性或方法,使用 parent::method()/self::method()
注意:$this->staticProperty(父类的静态属性不可以通过$this(子类实例)来访问,会有这样报错:PHP Strict Standards: Accessing static property Person::$country as non static in,PHP Notice: Undefined property: )
2.子类外部
1.子类名::method()
2.子类实例->method() (静态方法也可以通过普通对象的方式访问)
注意:子类实例->staticProperty(父类的静态属性不可以通过子类实例来访问,会有这样报错:PHP Strict Standards: Accessing static property Person::$country as non static in,PHP Notice: Undefined property: )

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template