37. Static Properties and Methods
Normally, class members belong to the object instance. Static members, however, belong to the class itself, not any specific object. They are shared across all instances.
Declaring Static Members
Use the static keyword before the property or method declaration.
Accessing Static Members
- From outside the class: Use the double colon (Scope Resolution Operator)
::. - From inside the class: Use
self::instead of$this->.
php
getCount(); // Output: 3 ?>When to use Static: For utility functions, helper methods, or counters/configurations that should be universal and not dependent on object creation (e.g., mathematical functions, shared config settings).