(1) static
Static keywords in the class is, describes a member is static, static can restrict the external access, because the static member is a class, is not part of any object instance, the other classes are inaccessible, only the instance of the class is shared, can be a certain program to protect the member. The static variables of a class, very similar to global variables, can be shared by instances of all classes, and the static methods of classes are the same, similar to global functions. The static method of the class can access the static properties of the class. It is also stated that the static member must be accessed using self, and using this will cause an error.
Using:: Calling a non-static method will result in an e_strict level error.
(2) const
A const is a keyword that defines a constant, similar to a # define in C, that defines a constant, and an error occurs if its value is changed in the program.
Illustrate the above code: (Note: The following code is from Phpe.net)
Class Counter
{
private static $count = 0;//defines a static property
Const VERSION = 2.0;//defines a constant
constructor function
function __construct ()
{
Self:: $count;
}
Destructors
function __destruct ()
{
Self:: $count--;
}
To define a static method
static function GetCount ()
{
Return self:: $count;
}
}
Create an instance
$c = new Counter ();
Perform printing
Print (Counter::getcount (). "
n "); Use the direct input class name to access the static method Counter::getcount
Print the version of the class
Print ("Version useed:".) Counter::version. "
n ");
Reference http://www.php100.com/html/php/hanshu/2013/0905/4424.html
Static and Const keywords in PHP5