a simple if-login question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maxim Vexler

    a simple if-login question

    if ((($value1 != null) || ($value1 != "")) && $value2 != "" && $value1
    != $value2) { ret false }

    if i omit the [value2 != ""] i would still get the same result, right?
    because I check if value1 != "" and then I check if value1!=value2
    i.e. :

    if ((($value1 != null) || ($value1 != "")) && $value1 != value2) { ret
    false }

    regards, maxim.
  • steve

    #2
    Re: a simple if-login question

    "Maxim Vexler" wrote:[color=blue]
    > if ((($value1 != null) || ($value1 != "")) && $value2 != "" &&[/color]
    $value1[color=blue]
    >
    > != $value2) { ret false }
    >
    > if i omit the [value2 != ""] i would still get the same result,[/color]
    right?[color=blue]
    >
    > because I check if value1 != "" and then I check if[/color]
    value1!=value2[color=blue]
    > i.e. :
    >
    > if ((($value1 != null) || ($value1 != "")) && $value1 != value2)[/color]
    { ret[color=blue]
    >
    > false }
    >
    > regards, maxim.[/color]

    I believe you are right. And you can simplify as well:
    ($value1 != null) || ($value1 != ""))
    is equal to:
    ($value1 != ’’) [[don’t need the two statements]]
    or if you have doubts, use:
    (strlen($value1 ) > 0)

    --
    http://www.dbForumz.com/ This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: http://www.dbForumz.com/PHP-simple-l...ict138481.html
    Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=462837

    Comment

    • Ian.H

      #3
      Re: a simple if-login question

      On Tue, 10 Aug 2004 23:28:15 -0400, steve wrote:
      [color=blue]
      > I believe you are right. And you can simplify as well:
      > ($value1 != null) || ($value1 != ""))
      > is equal to:
      > ($value1 != ’’) [[don’t need the two statements]]
      > or if you have doubts, use:
      > (strlen($value1 ) > 0)[/color]


      A variable assigned an empty string is _not_ the same as it being NULL.


      if (!is_null($valu e1) and strlen($value1) < 1) {



      Regards,

      Ian

      --
      Ian.H
      digiServ Network
      London, UK


      Comment

      • Ian.H

        #4
        Re: a simple if-login question

        On Wed, 11 Aug 2004 04:38:32 +0000, Ian.H wrote:
        [color=blue]
        > On Tue, 10 Aug 2004 23:28:15 -0400, steve wrote:
        >[color=green]
        >> I believe you are right. And you can simplify as well:
        >> ($value1 != null) || ($value1 != ""))
        >> is equal to:
        >> ($value1 != ’’) [[don’t need the two statements]]
        >> or if you have doubts, use:
        >> (strlen($value1 ) > 0)[/color]
        >
        >
        > A variable assigned an empty string is _not_ the same as it being NULL.
        >
        >
        > if (!is_null($valu e1) and strlen($value1) < 1) {[/color]


        Oops:


        if (!is_null($valu e1) and strlen($value1) > 0) {


        Better =)



        Regards,

        Ian

        --
        Ian.H
        digiServ Network
        London, UK


        Comment

        • Maxim Vexler

          #5
          Re: a simple if-login question

          steve wrote:[color=blue]
          > "Maxim Vexler" wrote:[color=green]
          > > if ((($value1 != null) || ($value1 != "")) && $value2 != "" &&[/color]
          > $value1[color=green]
          > >
          > > != $value2) { ret false }
          > >
          > > if i omit the [value2 != ""] i would still get the same result,[/color]
          > right?[color=green]
          > >
          > > because I check if value1 != "" and then I check if[/color]
          > value1!=value2[color=green]
          > > i.e. :
          > >
          > > if ((($value1 != null) || ($value1 != "")) && $value1 != value2)[/color]
          > { ret[color=green]
          > >
          > > false }
          > >
          > > regards, maxim.[/color]
          >
          > I believe you are right. And you can simplify as well:
          > ($value1 != null) || ($value1 != ""))
          > is equal to:
          > ($value1 != ’’) [[don’t need the two statements]]
          > or if you have doubts, use:
          > (strlen($value1 ) > 0)
          >[/color]

          in fact, and please correct me if I'm wrong :
          the logic (($value1 != null) || ($value1 != "")) is totally useless !
          because no matter what the input is you always get true from it, right?

          Comment

          Working...