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

    Join Date
    Dec 2016
    Location
    Lakewood, WA
    Posts
    219
    Rep Power
    17

    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. Maddening Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,453
    Rep Power
    9645
    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