At the heart of modern PHP is its object-oriented programming model. A class is a blueprint that defines the properties (variables) and methods (functions) its objects will have. You create an instance of a class using the new keyword, which also triggers the class's constructor, a special method named __construct() designed to initialize the new object's state. Many modern PHP constructors use promoted parameters, allowing properties to be declared and assigned directly in the constructor signature for more concise code.
Controlling who can access a class's internals is essential for writing maintainable code. PHP provides three access modifiers: public members are accessible from anywhere, protected members are accessible within the class itself and any subclasses that inherit from it, and private members are restricted to the defining class alone. These modifiers let you hide implementation details behind a clean public interface, which is a core principle of encapsulation.
Beyond instance-level data, PHP lets you define static properties and methods that belong to the class as a whole rather than to any particular object. Static members are accessed through the class name, such as Counter::$count, and are useful for shared counters, configuration values, or utility helpers that do not depend on per-instance state. The self keyword inside a static method refers to the same class, providing a way to reference static properties without resorting to the fully qualified name.