The difference between self and this keyword in PHP

王林
Release: 2023-04-07 19:10:01
Original
2897 people have browsed it

The difference between self and this keyword in PHP

The differences are as follows:

1. This cannot be used in static member functions, self can;

2. For static member functions/variables For access, it is recommended to use self instead of $this:: or $this->;

3. To access non-static member variables, self cannot be used, only this;

4. This should be used when the object has been instantiated, self does not have this restriction;

5. When used within a non-static member function, self suppresses polymorphic behavior and refers to the function of the current class; and this refers to the calling class's override function (if any).

Recommended tutorial: PHP video tutorial

The above is the detailed content of The difference between self and this keyword 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!