Home >Backend Development >PHP Tutorial >The difference between self and this keyword in PHP

The difference between self and this keyword in PHP

王林
王林Original
2019-11-08 18:03:302965browse

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!

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