Monday, July 18, 2011

there is more than one way to make sure a variable has a value

if (!$variable1) {
    $variable1 = 'default';
}

unless (defined($variable2)) {
    $variable2 = 'default';
}
can be done much more quickly as
$variable1 ||= 'default'; # true or
$variable2 //= 'default'; # defined or
i prefer the second

No comments:

Post a Comment