Static functions and variable are used to access Variables/functions in a global scope, like this:
echo myClass::myVariable;
echo myClass::myFunction();
When something is static, it can be accessed anywhere, and is very similar to a procedural type function, except it can use self and is contained in the classes scope.
class myClass{
static $myVariable = "myVar";
static function myFunction()
{
return "myFunc";
}
}
One of the ways to use this is to keep only one instance of a class, or a Singleton Method.
class myClass
{
static $class = false;
static function get_connection()
{
if(self::$class == false)
{
self::$class = new myClass;
}
else
{
return self::$class;
}
}
private function __construct()
{
// my constructor
}
// Then create regular class functions.
}
Because it has a private constructor, it cannot be instantiated with the new operator, so you are forced to call myClass::get_connection() to get a class. That function can make the new class (because it is a member of the class). Then it stores the class in a static variable, and if you call the function again, it will simply returned the created class.
In the end, the static keyword is used to keep things, well, static, in reference to scope. It means you don't want anything 'changing' because of the current scope. While the Singleton method stretches this a little, it keeps with the same idea that you always have the 'same' class, not matter what scope you are in.
PHP Documentation
Static Keyword
Scope Resolution Operator
StackOverflow Knowledge
How to Avoid Using PHP Global Objects
Share Variables Between Functions in PHP Without Using Globals
Making a Global Variable Accessible For Every Function inside a Class
Global or Singleton for Database Connection
PHP Classes: when to use :: vs. -> ?