Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#1 Requst handling 0 and ''

open-postponed
Brian Fioca
5
2006-01-26
2006-01-25
Anonymous
No

If you perform if(Request::getParameter(x)) and it is
either and '' or 0 it will return as false and the if
will fail.

Discussion

  • Brian Fioca
    Brian Fioca
    2006-01-26

    Logged In: YES
    user_id=1291914

    This is an interesting bug because it is related to the way
    PHP handles true and false. In PHP null, false, '', and 0
    are all equivalent.

    The easiest way around this is to never rely on implicit
    true or false evaluation. For example, always write code
    like if (request::getParameter(x) !== null) - in PHP === and
    !=== are extra explicit tests that compare for the literal
    evaluation. if (null === 0) will return false, for example.

    It is generally good practice to be as explicit as possible
    because it makes your code easier to read, however I agree
    this is rather confusing, and maybe we should look into
    using explicit === or !=== in the Request object.

     
  • Brian Fioca
    Brian Fioca
    2006-01-26

    • labels: --> WASP Framework Core
    • status: open --> open-postponed
     
  • Brian Fioca
    Brian Fioca
    2006-01-26

    • assigned_to: nobody --> bfioca