The use of double colons in PHP:

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.