在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

PHP对字符串中数值的处理。详见之前对另一个问题的回答,但简而言之:

"01a4" != "001a4"

如果你有两个包含不同数量字符的字符串,它们不能被认为是相等的。前导零很重要,因为它们是字符串而不是数字。

"01e4" == "001e4"

PHP doesn’t like strings. It’s looking for any excuse it can find to treat your values as numbers. Change the hexadecimal characters in those strings slightly and suddenly PHP decides that these aren’t strings any more, they are numbers in scientific notation (PHP doesn’t care that you used quotes) and they are equivalent because leading zeros are ignored for numbers. To reinforce this point you will find that PHP also evaluates "01e4" == "10000" as true because these are numbers with equivalent values. This is documented behaviour, it’s just not very sensible.

其他回答

在Java中

byte b = 0;
b++;

等于

byte b = 0;
b = b + 1;

但事实并非如此。实际上,你会得到一个编译器错误,因为加法的结果是int类型的,因此不能赋值给字节变量b。当使用复合运算符时,编译器会自动在这里插入一个类型转换。所以

b++;

就变成了

b = (byte) b + 1;

从技术上讲,WTF不是一种语言,而是一种架构。

http://www.6502.org/tutorials/6502opcodes.html#JMP

6502总成,间接JMP:

注意,间接跳转没有进位,因此: 间接跳转绝对不能使用 从最后一个字节开始的向量 一页的 例如,如果地址$3000包含$40,$30FF包含$80,$3100包含$50,JMP ($30FF)的结果将是控制权转移到$4080,而不是你想要的$5080,即6502从$30FF获取地址的低字节,从$3000获取高字节。

因此,在代码中添加一个字节可能会使间接跳转偏离目标。

我一直是PHP错误的忠实粉丝,当在一行中使用两个冒号时脱离上下文:

解析错误:语法错误,第3行/path/to/file/error.php中的T_PAAMAYIM_NEKUDOTAYIM异常

第一次遇到这种情况时,我完全被弄糊涂了。

Perl:

可以编写一个完全由标点符号组成的程序。

这是怎么回事?!

Perl中的字符串数学非常奇怪。

$ perl -E '$string = "a"; $string++; say $string'
b

$ perl -E '$string = "abc"; $string++; say $string'
abd

$ perl -E '$string = "money"; $string++; say $string'
monez

$ perl -E '$string = "money"; $string--; say $string'
-1