PHP scope qualifier double colon: usage _ PHP Tutorial

Source: Internet
Author: User
PHP scope qualifier double colon: usage. The dual-colon operator refers to the scope limitation operator ScopeResolutionOperator, which can access static, const, and attributes and methods that are rewritten in the class. Use the class name for calling when it is used outside the class definition. The dual-colon Operator is the Scope limitation Operator. Scope Resolution Operator can access static, const, and attributes and methods that are rewritten in the class.

Use the class name for calling when it is used outside the class definition. In PHP 5.3.0, you can use variables instead of class names.

Program List: use variables to define external access in the class
    
 
Program List: used outside the class definition ::
  
 

Program running result:

Fruit Color Red
Program List: call the parent method
  
 showColor();?>

Program running result:

Fruit::showColor() Apple::showColor()
Program List: Use the scope qualifier
  
 color;        }    }    class Banana    {        public $color;        public function __construct()        {            $this->color = "Banana is yellow";        }        public function GetColor()        {            return Apple::showColor();        }    }    $banana = new Banana;    echo $banana->GetColor();?>

Program running result:

Banana is yellow
Program List: call the method of the base class
    
 

Program running result:

show color

Resolution Operator can access static, const, and attributes and methods that are rewritten in class. If it is used outside the class definition, use the class name to call it ....

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.