<%! Static class Count { private static int count = 0; public static int GetCount () { count++; return count; } } %> <% out.print (Count.getcount ()); %>
Continuous access through the browser, will be output separately: 1,2,3,4,5,6,........
<?php class count{ private static $count = 0; public static function GetCount () {self :: $count + +; Return self:: $count; } } Echo Count::getcount (); ? >
Continuous access through the browser, will be output separately: 1,1,1,1,1,1,........
Summarize
1. The static variable of Java dies with the exit of the Java Virtual machine, and the static variable persists during the Java Virtual machine operation.
2, PHP static variable only for one request (a PHP file execution), PHP file execution, the static variable is also randomly extinct, again request (Execute the PHP file again), the static variable is recreated.
The static variable life cycle differs in PHP and Java