PHP OOPLesson 54Free preview
PHP Static Properties
This lesson is part of PHP · All levels
Summary
Static property is a property that is only stored once for the entire class, not for each object. All instances use and change the same property, so it's suitable for counting objects or shared configurations. The value is accessed using the self:: or class name followed by the $ sign.
Key points
- The static property is distributed to all instances, whereas the ordinary property is owned by each object.
- Declared with public static $name and accessed using self::$name or NameClass::$name.
- Static property does not require object creation to be accessed.
- Static properties are often used as a calculator or shared cache.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.