Home  >  Article  >  Backend Development  >  How to call the static method of the parent class in PHP

How to call the static method of the parent class in PHP

王林
王林Original
2020-09-28 13:26:243289browse

The method for a subclass in php to call the static method of the parent class: [parent::method()] or [self::method()]. If you want to call it outside the subclass, use [Subclass instance->method()].

How to call the static method of the parent class in PHP

Accessing parent class static member properties or methods within a subclass

(Recommended tutorial: php video tutorial)

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

Note: $this->staticProperty (static properties of parent class cannot be accessed through $this (subclass instance), an error will be reported:

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

External access to subclass

Subclass name::method()

Subclass instance->method() (static methods can also be accessed through ordinary objects)

Note: Subclass Class instance->staticProperty (static properties of the parent class cannot be accessed through subclass instances, an error will be reported:

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

Related recommendations: php training

The above is the detailed content of How to call the static method of the parent class in PHP. For more information, please follow other related articles on the PHP Chinese website!

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