The difference between ::, ->, self and $this operators in PHP

WBOY
Release: 2016-08-08 09:29:54
Original
794 people have browsed it

When accessing member variables or methods in a PHP class, if the referenced variable or method is declared as const (defining constant) or static (declaring static), then you must use the operator::,

and vice versa. If the referenced variable or method is not declared const or static, the operator -> must be used.

In addition, if you access a const or static variable or method from inside the class, you must use self-reference,

On the contrary, if you access a non-const or static variable or method from inside the class, then Must use self-referential $this.

The above introduces the differences between ::, ->, self, and $this operators in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

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!