Skip to content

Instantly share code, notes, and snippets.

@paveljanda
Created November 15, 2019 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paveljanda/cba6d31be920217c620289e54fed7c1c to your computer and use it in GitHub Desktop.
Save paveljanda/cba6d31be920217c620289e54fed7c1c to your computer and use it in GitHub Desktop.
Current Type variance changes breaks the Liskov substitution principle
<?php
interface FuelType
{
}
class Gas implements FuelType
{
public function burn(int $litres) {}
};
class Battery implements FuelType
{
public function discharge(int $kWh) {}
};
class Vehicle
{
public function drive(Gas $fuel)
{
$battery->burn(10);
}
}
class ElectricVehicle extends Vehicle
{
public function drive(FuelType $battery)
{
// do something
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment