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

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


当前回答

在PHP中:

echo 'foo' == 0;    // echos '1'
echo 'foo' == true; // echos '1'
echo 0 == true;     // echos '0'
$foo = 'foo';
echo $foo['bar']    // echos 'f'

PHP有一些最烦人的类型强制转换…

其他回答

在c++中,你可以做:

std::string my_str;
std::string my_str_concat = my_str + "foo";

但你不能:

std::string my_str_concat = "foo" + my_str;

操作符重载通常服从WTF。

在ColdFusion

Struct(又名Java HashMap)是通过引用传递的。

你可能认为其他数据类型的行为就像Java…

数组是按值传递的,wtf!

List只是一个普通的逗号分隔的字符串!

在Matlab中,以下内容可能会让你感到惊讶,特别是如果你习惯了Python:

>> not true

ans =

     0     0     0     0
>> not false

ans =

     0     0     0     0     0

这里有两个奇怪的特征。第一个是a b被解释为a('b'),因此非真被解释为not('true')。第二个奇怪的特征是没有任何字符返回0(大概是因为在matlab中没有false或true,只有0或1)。

任何东西都会自动将任何类名和成员名复数或单数。

例如,Linq-to-Sql

JavaScript日期全是WTF。

var d = new Date("1/1/2001");

var wtfyear = d.getYear(); // 101 (the year - 1900)
// to get the *actual* year, use d.getFullYear()

var wtfmonth = d.getMonth(); // 0
// months are 0-based!