when to use 2 equal signs and when to use 3

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lkrubner@geocities.com

    when to use 2 equal signs and when to use 3

    When I had these two lines in my code:


    if ($executed == "The command didn't exist") {
    $this->core->error("In CommandRenderAl lActionsInAnArr ay we sought
    the command '$commandName' but ExteriorCommand s could not find it. It
    returned the value: '$executed'.", "CommandRenderA llActionsInAnAr ray");



    I was getting this on screen:


    # CommandRenderAl lActionsInAnArr ay threw this error: In
    CommandRenderAl lActionsInAnArr ay we sought the command
    'checkToSeeIfTh isIsTheFirstLog in' but ExteriorCommand s could not find
    it. It returned the value: '1'.







    But if I change the first line to this:


    if ($executed === "The command didn't exist") {



    then it works correctly.


    Why does this need 3 equal signs? Why doesn't 2 suffice? I've done
    string comparisons before and I've never had to use 3 equal signs
    before.

  • Janwillem Borleffs

    #2
    Re: when to use 2 equal signs and when to use 3

    lkrubner@geocit ies.com wrote:[color=blue]
    > Why does this need 3 equal signs? Why doesn't 2 suffice? I've done
    > string comparisons before and I've never had to use 3 equal signs
    > before.
    >[/color]

    Have a close look at $executed. My guess is that it contains a boolean and
    because a non-empty string equals boolean true with the lose ==
    comparisation, you are getting the unexpected result. with === you are not
    only comparing the values but also the types.


    JW




    Comment

    • lkrubner@geocities.com

      #3
      Re: when to use 2 equal signs and when to use 3

      >>>>>>>>>>>>> >>[color=blue]
      > Why does this need 3 equal signs? Why doesn't 2 suffice? I've done
      > string comparisons before and I've never had to use 3 equal signs
      > before.[/color]

      Have a close look at $executed. My guess is that it contains a boolean
      and
      because a non-empty string equals boolean true with the lose ==
      comparisation, you are getting the unexpected re[color=blue][color=green][color=darkred]
      >>>>>>>>>>>>> >>[/color][/color][/color]

      In other words, if $executed is boolean true, it doesn't matter what
      the string is that I'm comparing it to, it still makes the if statement
      acts as if the statement is true?

      Comment

      Working...