|
Static KeywordTip
This page describes the use of the Declaring class properties or methods as static makes them accessible without needing an instantiation of the class. These can also be accessed statically within an instantiated class object. Static methodsBecause static methods are callable without an instance of the object created, the pseudo-variable $this is not available inside methods declared as static. Warning
Calling non-static methods statically throws an Error.
Prior to PHP 8.0.0, calling non-static methods statically were deprecated, and
generated an Example #1 Static method example
Static properties
Static properties are accessed using the
Scope Resolution Operator
(
It's possible to reference the class using a variable.
The variable's value cannot be a keyword (e.g. Example #2 Static property example
Output of the above example in PHP 8 is similar to: foo foo Notice: Accessing static property Foo::$my_static as non static in /in/V0Rvv on line 23 Warning: Undefined property: Foo::$my_static in /in/V0Rvv on line 23 foo foo foo foo |