Basic php knowledge: Class and object (4) range parsing operator (::)

Source: Internet
Author: User
Tags php basics
Php Basics: Class and object (4) range resolution operator (: :) range resolution operator (also known as Paamayim nekudow.im) or, more simply, a colon, it can be used to access static members, methods, and constants, and to access members and methods in the overwritten class.
When you access these static members, methods, and constants outside the class, you must use the class name.
In Hebrew, Paamayim nekudow.im indicates a double colon.

Use the: operator outside the class
Class MyClass {
Const CONST_VALUE = 'a constant value ';
}

Echo MyClass: CONST_VALUE;

The special keywords self and parent are used to access members or methods within the class.

Example:
Class OtherClass extends MyClass
{
Public static $ my_static = 'static var ';

Public static function doubleColon (){
Echo parent: CONST_VALUE. "n ";
Echo self: $ my_static. "n ";
}
}
OtherClass: doubleColon ();

When a subclass overrides the methods in its parent class, PHP will no longer execute the override methods in its parent class until these methods are called in the subclass. (Not nonsense? No, this is a difference between PHP and other mainstream languages ). This mechanism also applies to constructor and Destructor, overload and magic functions.

Class MyClass
{
Protected function myFunc (){
Echo "MyClass: myFunc () n ";
}
}

Class OtherClass extends MyClass
{
// Override the methods in the parent class
Public function myFunc ()
{
// But you can still call the overwritten method
Parent: myFunc ();
Echo "OtherClass: myFunc () n ";
}
}

$ Class = new OtherClass ();
$ Class-> myFunc ();




--------------------------------------------------------------------------------
?? Key ?? You must use the class name: when accessing static methods or members.
Note: PHP does not actively call the methods of the parent class, including constructor and Destructor.
See this text: http://163xiaofan.blog.163.com/blog/static/1713578020061027101820973

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.