Differences in usage of ::, ->, self, and $this operators in PHP

WBOY
Release: 2016-07-25 09:04:34
Original
929 people have browsed it
When accessing member variables or methods in a PHP class, if the referenced variable or method is declared as const (definition of constant) or static (declaration of static), then the operator:: must be used, otherwise the operator - >.

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 the operator:: must be used, otherwise the operator must be used ->.

In addition, if you access const or static variables or methods from within the class, you must use self-referencing self, otherwise you must use self-referencing $this.

In fact, if you have mastered the relevant knowledge of static classes, static variables, and constants in PHP, these are not difficult to understand.



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!