Static statics Properties for Java:
<%!static class Count { private static int count = 0; public static int GetCount () { count++; return count; }} %><%out.print (Count.getcount ()); Out.print ("
"); Out.print (Count.getcount ());%>
First time output 1, 2
After the refresh output 3, 4, the refresh will always be incremented.
If you restart the Tomcat server and turn it back on again, Output 1, 2
Static statically property of PHP
"; Echo Count::getcount ();
The first output 1, 2, the refresh will still output 1, 2
Comparison Summary:
1. The static property of Java dies with the exit of the Java Virtual machine, and the static property persists during the Java Virtual machine run, and is shared by all users.
2. The static property of PHP is only for one request (once PHP file execution), the PHP file executes, the static property is immediately extinct, again request (Execute the PHP file again), the static property is recreated, Therefore, PHP has no concept of shared static properties, only valid for a single request.
Add:
In addition, PHP has a static variable concept. A static property is something in a class, and a static variable is something in the method:
function count () {static $count = 0;//method defines static variable $count + +; return $count;} echo count (); echo "
"; echo count (); echo"
"; echo count ();
The first output of 1, 2, 3, after the refresh still output 1, 2, 3, indicating that PHP static variables and static properties, but also only for a single request valid.
Reference:
http://www.zhihu.com/question/35472851