Double colon (::) is used in PHP for: 1. Namespace delimiter; 2. Static method call; 3. Parent class access; 4. Constant access; 5. Delayed static binding. For example, MyNamespace::MyClass represents the namespace delimiter, while MyClass::myStaticMethod() represents a static method call.
Double colon (::) in PHP
Double colon (::) in PHP has the following Purpose:
1. Namespace separator
MyNamespace::MyClass
2. Static method call
MyClass::myStaticMethod()
##3. Parent class access
4. Constant access
5. Delayed static binding (LSB)
Example:
<code class="php">// 命名空间分隔符 namespace MyNamespace; class MyClass {} // 静态方法调用 class Foo { public static function myStaticMethod() { echo "This is a static method.\n"; } } Foo::myStaticMethod(); // 父类访问 class Bar extends Foo { public function myChildMethod() { echo "This is a child method.\n"; parent::myStaticMethod(); } } $bar = new Bar(); $bar->myChildMethod(); // 常量访问 class Baz { const MY_CONSTANT = 'Hello, world!'; } echo Baz::MY_CONSTANT;</code>
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!