Skip to content

Instantly share code, notes, and snippets.

@xphere
Created April 7, 2011 10:48
Show Gist options
  • Save xphere/907539 to your computer and use it in GitHub Desktop.
Save xphere/907539 to your computer and use it in GitHub Desktop.
Validation of Value Objects
<?php
// With static validation, no object is created if not valid.
if (Locale::isValid($localeName)) {
$locale = new Locale($localeName);
doFancyStuffWith($locale);
}
// With explicit validation
$locale = new Locale($localeName);
if ($locale->isValid()) {
doFancyStuffWith($locale);
}
// With implicit validation, constructor throws exception on invalid locale
$locale = new Locale($localeName);
doFancyStuffWith($locale);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment