Skip to content

Instantly share code, notes, and snippets.

@baileylo
Created January 31, 2012 17:50
Show Gist options
  • Save baileylo/1711831 to your computer and use it in GitHub Desktop.
Save baileylo/1711831 to your computer and use it in GitHub Desktop.
Which would you rather see?
<?php
// Which would you rather see
// Option 1 - double assignment
function isInCharge($name) {
$in_charge = false;
if ($name === 'Charles') {
$in_charge = true;
trigger_event('Play Charles In Charge theme song');
}
return $in_charge;
}
// Option 2 - gdgt safe
function isInCharge($name) {
if ($name === 'Charles') {
$in_charge = true;
trigger_event('Play Charles In Charge theme song');
} else {
$in_charage = false;
}
return $in_charge;
}
// Option 3 - Logan Safe
function isInCharge($name) {
if ($in_charge = ($name === 'Charles')) {
trigger_event('Play Charles In Charge theme song');
}
return $in_charge;
}
// Option 4 - double evaluation
function isInCharge($name) {
$in_charge = ($name === 'Charles');
if ($in_charge) {
trigger_event('Play Charles In Charge theme song');
}
return $in_charge;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment