Heim > Backend-Entwicklung > PHP-Tutorial > php 子类如何访问父类的静态方法

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-23 13:42:40
Original
1803 Leute haben es durchsucht

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: )

Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage