What is the significance of using static::method() in PHP inheritance?
Using `static::method()` in PHP inheritance allows for late static binding, meaning that the method called will be resolved at runtime based on the class where the method is actually called, rather than the class where the method is defined. This is useful when you want to call a method that may be overridden in a child class, ensuring that the correct version of the method is called dynamically.
class ParentClass {
public static function whoAmI() {
echo "I am the parent class.";
}
public static function display() {
static::whoAmI();
}
}
class ChildClass extends ParentClass {
public static function whoAmI() {
echo "I am the child class.";
}
}
ChildClass::display(); // Output: I am the child class.