Skip to content

Instantly share code, notes, and snippets.

@f3ath
Created October 25, 2017 21:21
Show Gist options
  • Save f3ath/fc9c56eb4e394c63a9e8c7a11b5e92e5 to your computer and use it in GitHub Desktop.
Save f3ath/fc9c56eb4e394c63a9e8c7a11b5e92e5 to your computer and use it in GitHub Desktop.
<?php
class IntCollection {
private $items = [];
function set(int $a) {
$this->items[] = $a;
}
function sum(): int {
return array_sum($this->items);
}
}
// Does this class violate LSP?
class PositiveIntCollection extends IntCollection {
function set(int $a) {
if ($a <= 0) {
throw new OutOfBoundsException('Only positives bitch!');
}
parent::set($a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment