A few days ago, I saw someone on Baidu Zhizhi asking about the usage of double colon:: in PHP, and I gave it to him at that time The answer is relatively concise because it is not convenient to type on a mobile phone! It suddenly occurred to me today, so here is a summary of the situations I encountered using double colon:: in PHP!
class test { static public $a; static public function b() {} }
If you want to call the static property $a, as follows
test::<span>$a</span>;
Note that a needs to be preceded by a $ sign, which is different from the -> sign!
If you want to call static method b, as follows
test::b();
2. When calling attributes or methods of your own class or parent class
First create a parent class
<span>class</span><span> test { </span><span>public</span> <span>function</span><span> b() {} }</span>
Then create a subclass that inherits the parent class
<span>class</span> tests <span>extends</span><span> test { </span><span>public</span> <span>function</span><span> cs() {} }</span>
When we need to call method b of the parent class
parent::b();
self::cs();
<span>$this</span>->cs();
What I encountered are probably the above two situations. If you encounter any other situations, you are welcome to come to Wang Yelou’s personal blog to add them!
Want to get updated content from Wang Yelou’s personal blog in a timely manner every day? Hurry up and add the WeChat public account "ly89cn", or scan the QR code below!
This article comes from Wang Yelou’s personal blog. The address of this article is: http://www.ly89.cn/detailB/57.html
Welcome to share this article, please indicate the source and address of this article when reprinting