在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在PHP中,必须显式地引用全局变量,并显式地使用这个->作为类变量。使重构变得有趣。如果不找到所有使用点,就不能将变量/参数提升为全局变量或类成员。
其他回答
对我来说,它绝对是INTERCAL中的PLEASE修饰符。 如果PLEASE出现的次数不够多,则认为程序不够礼貌,错误消息如下所示;如果太频繁,这个程序可能会被认为过于礼貌而被拒绝。
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.
可能已经说过了(也许这对一些人来说并不奇怪),但我认为这很酷:
在Javascript中,声明函数接受的参数只是为了方便程序员。通过函数调用传递的所有变量都可以通过关键字“arguments”访问。所以下面会提醒“world”:
<script type="text/javascript">
function blah(){
alert(arguments[1]);
}
blah("hello", "world");
</script>
注意,虽然这些参数看起来像是存储在数组中(因为您可以以与数组元素相同的方式访问对象属性),但事实并非如此。arguments是一个对象,而不是数组(因此,它们是存储在数值索引下的对象属性),如下例所示(typeOf函数来自Crockford的JavaScript补救页面):
argumentsExample = function(){
console.log(typeOf(arguments));
anArray = [];
console.log(typeOf(anArray));
anObject = {};
console.log(typeOf(anObject));
}
function typeOf(value) {
var s = typeof value;
if (s === 'object') {
if (value) {
if (typeof value.length === 'number' &&
!(value.propertyIsEnumerable('length')) &&
typeof value.splice === 'function') {
s = 'array';
}
} else {
s = 'null';
}
}
return s;
}
argumentsExample("a", "b");
在C或c++中,使用宏可以获得很多乐趣。如
#define FOO(a,b) (a+b)/(1-a)
如果传入FOO(bar++,4),它将使a增加两次。
一般来说,弱类型。
C:
printf("%c\n", 'a' + 3);
PHP:
echo 5 + "3";
还有太多其他语言。