PHP OOP Static Properties

PHP OOP – Static Properties
- Shared by all objects
- Accessed using
ClassName::$property Declared withstatickeyword
Basic Static Property Example
You don’t need to create an object.
Access Static Property Inside Class
Use self::$property inside the same class.
Modify Static Property
All Objects Share Same Static Property
All objects update one shared variable.
Static Property with Inheritance
Child class inherits static properties.
Override Static Property in Child
Each class keeps its own version.
Late Static Binding with Static Properties
Use static::$property for overriding behavior.
Wrong: Cannot Use $this with Static Property
Because $this refers to an object, not the class.
Practical Use Case – Configuration
Practical Use Case – Auto Incrementing ID
Summary (Easy to Remember)
| Feature | Meaning |
|---|---|
| static property | Belongs to class, not object |
| Access using | ClassName::$property |
| All objects share | Yes |
Cannot use $this | Yes |
| Good for | Counters, settings, shared data |
