PHP, OOP, Static

oop, php, static

Solution

class Foo
{
    public static $my_static = 'foo';
    public $my_non_static = 'bar';

    public function staticValue() {
        return self::$my_static;
    }

    public function nonStaticValue() {
        return self::$my_non_static;
    }
}

print Foo::$my_static . "\n"; // OK
print Foo::staticValue(). "\n"; // E_STRICT

print Foo::$my_non_static . "\n"; // Fatal
print Foo::nonStaticValue(). "\n"; // Fatal

`print Foo::$my_static . "\n";` is OK - static property accessed statically.

`print Foo::staticValue(). "\n";` gives E_STRICT - non-static method accessed statically, but not Fatal error, because this method doesn't access non-static properties.

Other two give Fatal error because non-static field cannot be accessed statically.

Problem

I am studying PHP,OOP and i am at Static, At this php.net/static i didnt understand this sentence ``` Calling non-static methods statically generates an E_STRICT level warning. ``` I did understand it's Valid for methods only (not for Properties) by the sentence above, but i didn't succeed to understand It practically, I'm glad if anything could please show me code that explains the sentence above, Wishing you a pleasant week.

Original source