There's a difference between a static variable and a static method.
Though making them static, only has real meaning inside an actual class.
Defining a static variable is not the same as defining it in the global scope because it still only exists inside a specific class.
For example:
Code:
class testingstatic
{
static $thisvar;
public $othervar;
public function __construct()
{
}
}
$thisvar is static in relation to the other variable in that object, but still needs an object reference to be accessed. $thisvar would not be directly available outside the class its defined in. You would need to actually specify the class this variable belongs to before you can use the variable.
You need to address it as: testingstatic::$thisvar or classname::$varname. Note that you need to include the $ variable identifier since its not part of an existing object or a constant.
defining a static method also requires a class name to access. While they can be accessed anywhere the class is defined, they are not truly global.
Also since there is no object instantiated, static methods cannot make use of the $this variable, nor can they access any of the object properties that are not also defined as static. PHP allows you to access non-static methods statically, but issues a warning stating it should not be done.
Basically defining variables as static should not be confused with global definitions. As static variables and methods still require the existence of a class definition to be meaningful. They do not exist in the global scope, but only within the scope of the class that contains them and its availability.
Defining a variable as static, (or public, private or protected for that matter) outside of a class definition has no meaning.
In structured programming there is no concept of static-ness. Everything is, as it is defined.
A static variable is also not quite a constant, since it can be changed at any time as opposed to a constant which remains the same during execution once it has been defined.
----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.
Web & Tech