class Foo
{
public static $staticVariable = 'foo';
public static function getVariableStatic() {
return self::$staticVariable;
}
public function getVariableNONStatic() {
return self::$staticVariable;
}
}
We can not access
$staticVariable
using an object directly:
$foo = new Foo();
print $foo->staticVariable;
This will produce the following error message:
Notice: Accessing static property Foo::$staticVariable as non static...
But there are several ways to access static variable using an object:
1. Using static getter method:
$foo = new Foo();
print $foo->getVariableStatic();
2. Using non-static getter method:
$foo = new Foo();
print $foo->getVariableNONStatic();
php.net:
A property declared as static cannot be accessed with an instantiated class object (though a static method can).