SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict rabbitdog's Avatar
    Join Date
    Jul 2001
    Location
    So. Tenn.
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A general question

    Anyone know the technical reason for having two operators for "and" and "or" ? I know that && has a higher precedence than AND, but that doesn't really explain why there are two....

    Thanks in advance.

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Probably another aftereffect of the different languages PHP pulls from. Just another way to do things.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Exactly. Some people prefer using actual English words for their operators. It's all about style. Same reason, I'd imagine, that you can use...

    echo("stuff");

    ...and...

    echo "stuff";

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by rabbitdog
    I know that && has a higher precedence than AND, but that doesn't really explain why there are two....
    umm, yes it does. the precedence is EXACTLY WHY there are 2. here, (http://www.php.net/manual/en/languag...rs.logical.php), in the comments, there's a few examples of the differences. i could show you some examples w/ Perl, but PHP can't do some of the things that Perl can where it makes a difference.

    use &&/|| in most cases, unless you find that they're giving you unexpected results. then you can try and/or.


    Originally posted by TWTCommish
    Exactly. Some people prefer using actual English words for their operators. It's all about style. Same reason, I'd imagine, that you can use...

    echo("stuff");

    ...and...

    echo "stuff";
    no, it's not just about style. there's most definitely a difference between &&/|| and and/or, and they'll give different results in some cases. so you can't just use one or the other b/c it's your "style."

    your example with echo, on the other hand, IS a "style" thing (though i'd say one is wrong, as the parentheses are superfluous ) b/c the 2 ways will work EXACTLY the same. well, except you can't do echo $var, $var; if you use parentheses. but, other than that, the results will be the same with both, unlike with the logical operators.


    Originally posted by freddydoesphp
    Just another way to do things.
    see above.


    Originally posted by freddydoesphp
    Probably another aftereffect of the different languages PHP pulls from.
    true.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  5. #5
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, the parentheses are pointless...but it's virtually the same thing anyway. PHP's got something like a dozen functions which are just aliases for others...simply because it can't really hurt much, I suppose.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •