The scope resolution operator (also known as Paamayim Nekudotayim) or, more simply, a pair of colons, can be used to access static members, methods, and constants, and can also be used to access members and methods in the overridden class.
When you access these static members, methods, and constants outside of the class, you must use the name of the class.
The Paamayim Nekudotayim in Hebrew is the meaning of double colons.
Use outside of class:: operator
Class MyClass {
Const Const_value = ' A constant VALUE ';
}
Echo Myclass::const_value;
The two special keywords, self and parent, are used to access members or methods within a 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::d Oublecolon ();
When a subclass overrides a method in its parent class, PHP no longer executes methods that have been overridden in the parent class until the methods are called in the subclass. (Is it nonsense?) No, this is the difference between PHP and other mainstream languages). This mechanism is also used for constructors and destructors, overloads, and magic functions.
Class MyClass
{
protected function MyFunc () {
echo "Myclass::myfunc () n";
}
}
Class Otherclass extends MyClass
{
Overriding methods in a parent class
Public Function MyFunc ()
{
But you can still call methods that have been overridden
Parent::myfunc ();
echo "Otherclass::myfunc () n";
}
}
$class = new Otherclass ();
$class->myfunc ();
--------------------------------------------------------------------------------
?? Focus?? Be sure to use the class name:: Method when accessing static methods or members.
It is also important to note that PHP does not actively invoke the methods of the parent class, including constructors and destructors.
See this text: http://163xiaofan.blog.163.com/blog/static/1713578020061027101820973
The above introduces the basic accounting exercises and case answer PHP basic knowledge: Class and object 4 scope resolution operator::, including the basic accounting exercises and case answers to the content, I hope the PHP tutorial interested in a friend helpful.