This page describes defining static methods and properties with the static keyword. Static can also be used to define statically variable and late static bindings.
Declaring a class property or method as static can be accessed directly without instantiating the class. Static properties cannot be accessed through an object that a class has instantiated (but static methods can).
To be compatible with PHP 4, if no access control is specified, the properties and methods default to public.
Because static methods do not need to be called through an object, the pseudo-variable $this is not available in a static method.
A static property cannot be accessed by an object through the operator.
Invoking a non-static method in a static manner results in an e_strict level error.
Just like all other PHP static variables, static properties can only be initialized to literals or constants, and expressions cannot be used. You can initialize a static property to an integer or an array, but you cannot initialize it to another variable or function return value, or point to an object.
Example #1 Static Property Example
Class foo{public static $my _static = ' Foo '; Public Function Staticvalue () { return self:: $my _static; }} Class Bar extends foo{public function foostatic () { return Parent:: $my _static; }} Print Foo:: $my _static. ' <br> '; $foo = new Foo ();p rint $foo->staticvalue (). ' <br> ';p rint $foo->my_static. ' <br> ';p rint $foo:: $my _static. ' <br> '; $classname = ' Foo ';p rint $classname:: $my _static;print Bar:: $my _static. ' <br> '; $bar = new bar ();p rint $bar->foostatic (). ' <br> ';