Skip to content
Advertisement

could static members use nonstatic members and vice versa?

could i use nonstatic members inside a static method?

eg.

 $this->nonStaticProperty
 $this->nonStaticMethod()

and vice versa that is to say use static members inside non-static methods?

Advertisement

Answer

From http://php.net/manual/en/language.oop5.static.php

Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. A property declared as static can not be accessed with an instantiated class object (though a static method can).

You can’t use non-static members in a static function, since they’re outside the function’s scope. But you can use static members in a non-static function.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement