Skip to content

Instantly share code, notes, and snippets.

@till
Created November 8, 2012 16:09
Show Gist options
  • Save till/4039765 to your computer and use it in GitHub Desktop.
Save till/4039765 to your computer and use it in GitHub Desktop.
<?php
// not so great:
if ($blah) {
$doSomething;
} else {
throw Exception();
}
// better:
// be explict
// no need to overcomplicate with else
if (false === $blah) {
throw Exception();
}
$doSomething;
// Also good in methods:
function foo()
{
if ($somethingDidntWork) {
return; // this exits from the method, no need to "else"
}
$doSomething;
andMore();
return 'whatever';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment