The range resolution operator (also known as Paamayim nekudow.im) or, more simply, a colon can be used to access static members, methods, and constants, as well as 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