How can I have a variable which is global to whole application such as static variables of Java (I think static variables in php is different than of java).
You can use the $GLOBALS superglobal array. However, I think that it is better to explicitly declare a global variable as global within function scope, or to pass it to the function, say by reference. Static variables in PHP share much in common with those in Java if you use them in the context of a class.