V. Scope resolution operator (::)
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 override members and methods in a class.
When you access these static members, methods, and constants outside of the class, you must use the name of the class.
It seems strange to choose Paamayim Nekudotayim as the name of the operator. However, this is the decision made by the Zend development team when writing Zend Engine 0.5 (used in PHP 3). In fact, the word in Hebrew is the meaning of a double colon.
Example#1 used outside the class:: operator
<? PHP 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#2:: From inside the class definition
<? php class Otherclass extends MyClass { public static $my _static = ' static var '
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. This mechanism is also used for constructors and destructors, overloads, and magic functions.
Example#3 calling the parent class method
<?PHPclassMyClass {protected functionMyFunc () {Echo"Myclass::myfunc () \ n"; } } classOtherclassextendsMyClass {//overriding methods in a parent class Public functionMyFunc () {//but you can still call methods that have been overriddenParent::MyFunc (); Echo"Otherclass::myfunc () \ n"; } } $class=NewOtherclass ();$class-MyFunc ();?>
Learning classes and objects for beginners in PHP (4)