Created
October 25, 2017 21:21
-
-
Save f3ath/fc9c56eb4e394c63a9e8c7a11b5e92e5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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