Home>Article>Backend Development> What does :: mean in PHP?

What does :: mean in PHP?

青灯夜游
青灯夜游 Original
2019-05-17 19:27:26 16238browse
Recommended manual: php complete self-study manual

In PHP, the double colon (::) operator is a range parsing operator. Also scoped operator. It is a static reference to a method in the class and can access static, const, and overridden properties and methods in the class.

When php calls internal static members of a class, or calls between classes, two colons (::) must be used.

Note: The "::" symbol can be considered similar to the "." in C language, and it is more like the :: class range operator in C (Perl).

Example:

class A{ static $count = 0; static function haha(){ // } function diaoyoug(){ self::haha(); self::$count; } } a.b.c; /* C语言中的 */ a::b::c(); // C++ 中的函数 $a::b::c; # Perl 5中的标量

If the double colon (::) operator is used outside the class definition, it must be called using the class name. In PHP 5.3.0, you can use variables instead of class names.

Example: Using the double colon (::) operator outside the class definition

Output:

Fruit Color Red
Related article recommendations:
1. Introduction to the meaning of the double colon::range parsing operator in php
2. The difference between the double colon range parsing operator and the arrow-> operator in php
Related video recommendations:
1. Dugu Jiujian (4)_PHP video tutorial
##

The above is the detailed content of What does :: mean 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