🐘 PHP
Intermediate
What is late static binding in PHP?
Answer
Late static binding (LSB), enabled by static::, allows a method defined in a parent class to reference the class it is called on at runtime, not the class where the method is defined. self:: always resolves to the class in which the method is written — even if a child class overrides the property. static:: resolves to the class that was actually called. Example: if ParentClass has a static factory method using return new static();, calling ChildClass::create() returns a ChildClass instance. Using return new self(); would always return a ParentClass instance. LSB is essential for building fluent query builders, active record patterns, and other class-hierarchy-aware patterns.