php5| keyword
Many object-oriented ideas have been added to the PHP5, and the object-oriented approach of PHP5 is close to the object-oriented idea of Java. Here we have a description of the static and const keyword functions in PHP5, and hope to be of help to learn PHP5 's friends.
(1) static
The static keyword is in the class, describes a member is static, static can restrict access to external, because the static members belong to the class, is not part of any object instances, other classes are inaccessible, only to instances of the class to share, can be a certain program to protect the members. A static variable of a class, very similar to a global variable, can be shared by instances of all classes, and the static method of the class is the same, similar to the global function. Static methods of a class can access the static properties of a class. Additionally, static members must be accessed using self, and using this will make an error.
(for the similarities and differences between this and self, please refer to: http://blog.csdn.net/heiyeshuwu/archive/2004/11/03/165828.aspx)
(2) const
Const is a keyword that defines a constant, similar to the #define in C, can define a constant, and if it changes its value in the program, an error occurs. The
provides an example of the above code: (Note: The following code comes from Phpe.net)
<?php
Class Counter
{
private static $count = 0 ;//define a static property
const VERSION = 2.0;//Define a constant
//constructor
function __construct ()
{
Self:: $count + +;
}
//destructor
function __destruct ()
{
Self:: $count-;
&NBSP}
//Define a static method
static function GetCount ()
{
return self::$ Count
}
}
//Create an instance
$c = new Counter ();
//Execute print
(counter::getcount) print (). "<br>\n"); Use the direct input class name to access the static method Counter::getcount
///print version of the class
print ("Version useed:". Counter::version. "<br>\n");
?
Well, basically here, the heart know that something will be clear, but I feel that I still have a little understanding of static, please expert advice!
My mailbox: heiyeluren@163.com
Writetime 2004-11-3 21:00