Differences between phpstatic static variables and javastatic static variables
Static attributes of 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());%>
Output 1 and 2 for the first time
After the refresh, the output is 3 and 4. the refresh will increase progressively.
If you enable tomcat server again after it is restarted, resend 1 and 2
Static attributes of php
"; Echo Count: getCount ();
Output 1 and 2 for the first time. refresh will still output 1 and 2
Comparison Summary:
1. the static attribute of java disappears along with the exit of the java virtual machine. during the running of the java virtual machine, the static attribute always exists and all users share the static attribute.
2. php's static attribute is only for one request (one php file execution). after the php file is executed, the static attribute disappears immediately and is requested again (execute the php file again ), the static property is re-created. Therefore, the static property of php is not shared and only valid for a single request.
Supplement:
In addition, php also has the concept of static variables. Static attributes are in the class, and static variables are in the method:
Function count () {static $ count = 0; // defines the static variable $ count ++ in the method; return $ count;} echo count (); echo"
"; Echo count (); echo"
"; Echo count ();
Output 1, 2, and 3 for the first time, and output 1, 2, and 3 after Refresh. it indicates that the static variables of php are the same as those of static attributes and are only valid for a single request.
Refer:
Http://www.zhihu.com/question/35472851