Home > Backend Development > PHP Tutorial > What are the differences between the static keyword and the self keyword in PHP?

What are the differences between the static keyword and the self keyword in PHP?

云罗郡主
Release: 2023-04-04 10:22:01
Original
3289 people have browsed it

In PHP learning, many people confuse the static keyword and the self keyword. Many people think that the static keyword and the self keyword are the same. So are the static keyword and the self keyword the same? Let's summarize what are the differences between the static keyword in PHP and the self keyword?

What are the differences between the static keyword and the self keyword in PHP?

Regarding the static keyword and the two terms self keyword, I believe many people will encounter it when getting started with PHP. Some people do not understand these two keywords. A lot. If you are learning PHP now, you must learn the difference between these two keywords.

1: What is the static keyword? What is the self keyword?

1. What is the static keyword?

In the PHP Chinese website manual, the description of the self keyword is that after setting the attributes of the class to static, you can access the static attributes without instantiating the object.

2.What is the self keyword?

The self keyword is used in object methods, and of course points to the current object. If it is in a class method, the self keyword represents the current class.

2: What are the differences between the static keyword in PHP and the self keyword?

1. The self keyword is an intra-class pointer, and self itself is also a strong For probes, let’s not worry about whether we have written a parent class, but the attributes of self all point to static.

2. In the static keyword, if you encounter an attribute that overrides the parent class, generally speaking, you will access the subclass.

The above is a complete introduction to the static keyword in PHP and the differences between it and the self keyword. If you want to know more about php programming from entry to mastery full set of video tutorials, please pay attention to the PHP Chinese website.


The above is the detailed content of What are the differences between the static keyword and the self 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