1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Lakewood, WA
    Rep Power

    When is a var empty?

    I'm working with a function that someone else wrote, cleaning it up a bit and fixing some funk that is probably the result of inexperience on the part of the original author. It's a function that converts DMS to decimal, and it's really slick in that in can accept lots of funky DMS formats and parse them - very nice yet needs work...

    So, remembering that we are working with strings and a lot of regex,

    if ($coord != "") { something }

    Can't I use:

    if (!$coord) { something }

    Is there different types of an empty var when dealing with strings?
  2. #2
  3. Backwards Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    Obviously an empty string is false, but what people often forget is that "0" is false too. "0.0" is not but it helps to think of both the same way. So if $coord can legitimately be zero then writing !$coord is not safe.

IMN logo majestic logo threadwatch logo seochat tools logo