Ford, Mike <M.Ford@xxxxxxxxxxxxxx> wrote: > (someone else wrote:) > > $browser = get_browser(null, TRUE); > > if (isset($browser['ismobiledevice']) && ($browser['ismobiledevice'] == TRUE)) { > > $isMobile = TRUE; > > } > > else { > > = FALSE; Mike's remarks below notwithstanding, I think something fell off here. > > } > > unset($browser); > > Argh!, Argh!, Argh! -- two of my pet hates in one snippet! Tell us how you really feel, Mike. :)) > Comparing something ==TRUE is almost always unnecessary, and > absolutely always when it's used as an element of a Boolean > expression: if x evaluates to TRUE, x==TRUE is also TRUE, and if it > evaluates to FALSE x==TRUE is also FALSE, so the comparison is > unnecessary, redundant and wasteful. Just use x. The only time I'd be looking at whether content of $somearray['somekey'] == TRUE is when it's possible that it may contain something other than TRUE or FALSE, and somehow my code *cares* whether it does. In this case, we do not, your rant holds. > And why use an if test on a Boolean value to see if it's TRUE or > FALSE, just so you can assign TRUE or FALSE?? Since the thing you're > testing has the value you want in the first place, just flipping > assign it! This is most egregious. > $isMobile = isset($browser['ismobiledevice']) && $browser['ismobiledevice']; This would even be a case where I'd opt for: $isMobile = @$browser['ismobiledevice']; since if it *isn't* set, it's still falsy, with the rather strong caveat of don't use @ indiscriminantly. > </rant> Cheers! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php