What do two colons mean in PHP?

I don't know what it's doing when we have this situation:

Foo::Bar

It looks like a path.


That's (generally) for accessing a static method or property in a class. It's called the scope resolution operator, or Paamayim Nekudotayim (which leads to some amazingly confusing error messages!). See http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php.


The :: operator is the scope resolution operator. It is used to access class constants or static properties and methods, either from outside the class:

ClassName::CONSTANT_VALUE
ClassName::staticMethod()

Or within a class method to reference the same or a parent class using self and parent :

self::CONSTANT_VALUE
self::staticMethod()
parent::CONSTANT_VALUE
parent::staticMethod()

范围解析运算符(::)双冒号是允许访问类的静态常量和重写属性或方法的标记。

<?php
class A {

public static $B = '1'; # Static class variable.

const B = '2'; # Class constant.

public static function B() { # Static class function.
    return '3';
}

}

echo A::$B . A::B . A::B(); # Outputs: 123
?>
链接地址: http://www.djcxy.com/p/1746.html

上一篇: PHP标记名称T的含义是什么?

下一篇: PHP中的两个冒号意味着什么?