Usage of double colon:: in PHP, php colon usage_PHP tutorial

WBOY
Release: 2016-07-12 09:05:29
Original
1127 people have browsed it

Usage of double colon:: in PHP, usage of colon in php

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!

Usage of double colon:: in PHP, php colon usage_PHP tutorialclass test { static public $a; static public function b() {} }


If you want to call the static property $a, as follows

test::<span>$a</span>;
Copy after login

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();
Copy after login


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>
Copy after login

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>
Copy after login

When we need to call method b of the parent class

parent::b();
Copy after login
When we need to call our own method cs, there are two methods
self::cs();
Copy after login
<span>$this</span>->cs();
Copy after login


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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1068265.htmlTechArticleUsage of double colon:: in PHP, php colon usage A few days ago, I saw someone asking about PHP in Baidu Know Regarding the use of double colons::, the answer I gave him at the time was relatively concise because it was not convenient to type on a mobile phone...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template