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

╄→尐↘猪︶ㄣ 提交于 2019-11-28 11:26:02

问题


I can't get working this conditional expression

<!--#if expr="$DOCUMENT_NAME!=index.html || $DOCUMENT_NAME!=links.html" -->

while this one without ! before = works perfect

<!--#if expr="$DOCUMENT_NAME=index.html || $DOCUMENT_NAME=links.html" -->

What's the problem? I get no error simply != doesn't work though || with other condition but works for single condition.


回答1:


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.



来源:https://stackoverflow.com/questions/12169639/why-ssi-condition-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!