Why SSI condition != || != doesn't work?

前端 未结 1 1732
粉色の甜心
粉色の甜心 2020-12-22 02:36

I can\'t get working this conditional expression


while

相关标签:
1条回答
  • 2020-12-22 03:04

    This is because = and != are hardly the same operator. Note that, by De Morgan's law (which I also explained in this old post),

    a != b || c != d
    

    is equivalent to

    a = b && c = d
    

    which is never true for x = a && x = b where a != b.

    Changing the binary operator requires changing the conditionals as well to be equivalent.

    Thus, by the above logic,

    $DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html
    

    is equivalent to

    $DOCUMENT_NAME=index.html && $DOCUMENT_NAME=links.html
    

    which cannot be true as $DOCUMENT_NAME can be "index.html" or "links.html" but not both.

    However, the 2nd snippet,

    $DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html
    

    "works" because there is not the logical never-true fallacy mentioned above. It will be true when $DOCUMENT_NAME is either "index.html" or "links.html".


    Some languages/values will violate the above equivalency .. but that is another topic.

    0 讨论(0)
提交回复
热议问题