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

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

王林
Release: 2023-03-06 07:42:01
Original
3525 people have browsed it

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()
Copy after login

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: )
Copy after login

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: )
Copy after login

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!

Related labels:
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