-
Book Overview & Buying
-
Table Of Contents
Learning PHP Data Objects
By :
In all the examples in this appendix, we are using instances (objects) of classes, which modeled real-life entities. However, in PHP5 it is possible to use static properties and methods. Static properties are variables that are common to all the instances of the given class so that, if a static property is changed, it will get changed for all objects belonging to the class.
A static property is declared just like a regular one, but with a special static keyword:
class DataModel
{
public static $conn = null;
}
The static properties can be accessed without even creating an instance of the class:
if(!DataModel::$conn) {
echo 'Connection not established!';
}
The syntax for accessing a static property is as follows: the class name, then double semicolon, and then the property's name. Note that with static properties (unlike with regular properties), the dollar sign, $, sign must be present.
Static methods, just like static properties, can be accessed...
Change the font size
Change margin width
Change background colour