Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active August 23, 2023 00:21
Show Gist options
  • Save mcsee/0a519a375e302a5d25ec09185bf95312 to your computer and use it in GitHub Desktop.
Save mcsee/0a519a375e302a5d25ec09185bf95312 to your computer and use it in GitHub Desktop.
<?
final class Date{
function __construct($aMonthDay, $aMonth) {
if (!$aMonth->includes($aMonthDay)) {
throw new InvalidDateException($aMonthDay, $aMonth);
}
...
}
$day30 = new Day(30);
$year2020 = new Year(2020);
$feb2020 = new YearMonth(2, $year2020);
$invalidDate = new Date($day30, $feb2020);
// will raise an exception.
// No, It will not coerce to March,1st
// or do "under the rug magic" to coverup the programmer contract violation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment