PHP spooky Operator Precedence ____php by logical XOR or operator

Source: Internet
Author: User

In the logical operator of PHP, XOR represents a logical XOR or

$a XOR $b

Results

Returns true if the $a and $b have and only one is true, or False if all are true or false.

However, when testing the XOR operator, a little problem was found
error Condition 1

<?php
        $a = False xor true;
        Var_dump ($a);
? >

result 1

Boolean false

Situation 2

<?php
        $a = True xor false;
        Var_dump ($a);
? >

Result 2

Boolean true

What the hell is going on here?

Let's change the way the XOR operator is tested
Situation 3

<?php
        echo False xor true;
? >

result 3

1

So there's no problem, so what's wrong with the first two cases?

Situation 4

<?php
        $a = (false xor true);
        Var_dump ($a)
?>

Result 4

Boolean true

This is true, and visibility should be caused by operator precedence.

In PHP, theoperator precedence of and, or, XOR is lower than = , in which case it would be nice to add a parenthesis ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.