在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“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.

其他回答

很久以前,我曾经用BUT子句构建过一种语言。

c# yield语句,并不奇怪,但非常有用。

http://msdn.microsoft.com/en-us/library/9k7k7cf0 (VS.80) . aspx

闲聊:

在类Test中有一个类方法,返回一个常量字符串:

method1
    ^ 'niko'

无论发生什么,这个方法都会不断返回字符串'niko'。但事实并非如此。

s := Test method1 

(设置为“niko”。)

s at: 4 put: $i.

(设置为“niki”。)

s := Test method1

(再次设置为“niki”。)

因此,第二行代码永久地将method1更改为返回'niki'而不是'niko',即使方法的源代码没有更新。

在类C语言(包括C本身)中,你可以使用“向下到”操作符:

for (x = 20; x --> 0;) {
    print x;
}

这将打印从19到0的数字。

我有点纠结:

1;

在perl中,模块需要返回true。