class Transport{ public static $model = 'transport'; public static function getModel() { return self::$model; } } class Car extends Transport{ public static $model = 'car'; } echo Car::getModel(); // 'transport'
return self::$model – points to the current class, so the result is ‘transport’, this mechanism is also called “Early static binding“.
class Transport{ public static $model = 'transport'; public static function getModel() { return static::$model; } } class Car extends Transport{ public static $model = 'car'; } echo Car::getModel(); // 'car'
If the word “self” is replaced by “static“, then we get “late static binding“, i.e. the connection will be established with the class that calls this code, as a result we get the value “car”.