The range resolution operator (also known as Paamayim Nekudotayim) or, more simply, a pair of colons, can be used to access static members, class constants, and also to override properties and methods in a class.
Use the class name when referencing these items outside of the class definition.
From PHP 5.3.0, you can refer to a class by using a variable that cannot be a keyword (such as self,parent and Static).
It seems strange to have Paamayim Nekudotayim chosen as the name of the double colon operator. However, this is the decision the Zend development team made when writing Zend Engine 0.5 (used in PHP 3). In fact, the word means double colon in Hebrew.
Example #1 used outside of a class:: operator
<?php
class MyClass {
Const Const_value = ' A constant VALUE ';
}
$classname = ' MyClass ';
echo $classname:: Const_value; From PHP 5.3.0
, echo myclass::const_value;
? >
Self, parent, and static these three special keywords are used to access the properties or methods within the class definition.
Example #2 used within the class definition::
<?php
class Otherclass extends MyClass
{public
static $my _static = ' static var ';
public static function Doublecolon () {
echo parent::const_value. "\ n";
echo Self:: $my _static. "\ n";
}
}
$classname = ' Otherclass ';
echo $classname::d Oublecolon (); From PHP 5.3.0
Otherclass::d Oublecolon ();
? >
Example #3 The method of calling the parent class
<?php
class MyClass
{
protected function MyFunc () {
echo "myclass::myfunc () \ n";
}
}
class Otherclass extends MyClass
{//
overrides the definition public
function MyFunc () of the parent class ()
{
//But still can invoke the overridden method in the parent class
Parent::myfunc ();
echo "Otherclass::myfunc () \ n";
}
}
$class = new Otherclass ();
$class->myfunc ();
? >