class Foo
{
public static $my_static = 'foo';
public static function staticValue() {
return self::$my_static;
}
}
$foo = new Foo();
print $foo->staticValue() . "\n";
print $foo->my_static . "\n";
Why the static attribute is not accessible while static resources are accessible using object in PHP.It is only accessible using ‘::’.
Because you have 2 “scopes” one is the “object” and one is the “static” within every class.
So the same problem occurs of you want to execute a normal method within a static method.
For example:
That is because the you are in a static context and the object context is not accessable from there.
I think, more it can not be said about this.
See it like you have a house with 2 familys which lives in it and the doors between them can NEVER be open.
You have one global house which is the class and then family 1 which is the object scope and finally family 2 which is the static scope.
Maybe this helped.