Double Colon in PHP:: Usage
A few days ago in Baidu know inside see someone asked PHP double colon:: The use, at that time to his answer is relatively concise because the phone typing is not convenient! It suddenly comes to mind today, so here's a summary of the double colons I've encountered:: What to use in PHP!
one, when static properties and static methods are called
:: The same as the role, but the use of different objects! :: Refers to static methods or properties within a class, and does not need to be instantiated!
Create a class and create a static property of $ A, a static method B, as follows:
class Test { staticpublic$a; Static Public function B () {}}
If you want to call the static property $ A, the following
Test::$a;
Note that a $ symbol is required before a, which is not the same as the symbol!
If you want to call static method B, the following
Test::b ();
Two, when calling a property or method of its own class or parent class
First create a parent class
class Test { publicfunction B () {}}
Then create a subclass to inherit the parent class
class extends Test { publicfunction cs () {}}
When we need to call method B of the parent class
Parent::b ();
When we need to call our own method CS, there are two ways
Self::cs ();
$this->cs ();
I met is probably the above two cases, if you have encountered any other situation, welcome to Wang Yip Building's personal blog to add ha!
Want to get the updated content of Wang Yip's personal blog in time every day? Quickly add the public number "LY89CN", or scan the QR code below!
This article originates from the personal blog of Wang Ye Building, this article address: http://www.ly89.cn/detailB/57.html
Welcome to share this article, reprint please indicate the source and address of this article