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

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


当前回答

在PHP中

var_export('false' == 0);       // true

var_export('false' == true);    // true

var_export('false' == false);   // false

EDIT

正如@Kobi提到的,这可能发生,因为语言将任何值解释为“TRUE”,除了“FALSE”,但在PHP中不是这样,在那里事情比你想象的更奇怪!

这个案例在PHP手册的“字符串转换到数字”一章中有完整的记录,它说:

如果字符串以valid开头 数值数据,这就是值 使用。否则,该值为0 (零)。

这里有一个例子:

print (int) 'zero';    // 0
print (int) 'false';   // 0
// but
print (int) '1 - one'; // 1

附注:我认为这种隐式类型转换弊大于利。

其他回答

PHP作为一门完整的语言基本上是WTF。

语言定义(参见www.php.org)不是由语法或标准定义的,而是由一堆“你可以写这个例子”的部分(当然,你可以写其他东西,只是猜测泛化)定义的,诚实的用户说“但它做了这种古怪的事情……”。

在使用我们构建的PHP解析器时,我经常会遇到一些故障。这是最新的消息:

 "abc$A[define]def"

现在,PHP是PERL的一个(非常糟糕的)副本,因此它允许用隐式变量替换构造字符串。字符串中的$X表示“将$X的值插入字符串”,相当于“abc”。$ X。"def",其中"."是PHP的字符串连接操作符。

字符串中的$A[7]表示“将数组$A的第七个槽的值插入字符串”,相当于“abc”。美元[7]。“def”。

现在,语言(网站)清楚地说“定义”是一个关键字,你不能 只要你能找到合适的表达就用它。那么上面包含“define”的宝石做什么呢?抛出语法错误?不,那样说得通。

不,它实际上的意思是:

 "abc" . $A["define"] . "def"

只有当你在一个字符串的简单数组访问中写一个看起来像标识符(关键字或不是!)的东西时,它才会这样做。在语言的其他地方没有这种行为。 什么,写“abc$A["define"]def”是不合理的,所以PHP发明者不得不把它扔进去?得了吧。(更严重的是,“字符串中有复杂的数组访问”,当然它的工作方式不同。查看"abc{$A[define]}def";根据PHP网站,这是非法的。

(PHP数组是关联哈希表,因此根据名称查找数组(嗯,哈希表)成员并不是一个糟糕的想法)。

语言中充满了这样的陷阱。如果你喜欢“天哪,看看我今天在子程序下发现了什么蠕动的东西”,你应该切换到PHP。

Perl的许多内置变量:

$# — not a comment! $0, $$, and $? — just like the shell variables by the same name $ˋ, $&, and $' — weird matching variables $" and $, — weird variables for list- and output-field-separators $! — like errno as a number but strerror(errno) as a string $_ — the stealth variable, always used and never seen $#_ — index number of the last subroutine argument... maybe @_ — the (non)names of the current function... maybe $@ — the last-raised exception %:: — the symbol table $:, $^, $~, $-, and $= — something to do with output formats $. and $% — input line number, output page number $/ and $\ — input and output record separators $| — output buffering controller $[ — change your array base from 0-based to 1-based to 42-based: WHEEE! $} — nothing at all, oddly enough! $<, $>, $(, $) — real and effective UIDs and GIDs @ISA — names of current package’s direct superclasses $^T — script start-up time in epoch seconds $^O — current operating system name $^V — what version of Perl this is

还有很多这样的东西。点击这里阅读完整列表。

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

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

6502总成,间接JMP:

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

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

这是我的两分钱。在c++中:

int* t = new int(15);
delete t;

在Javascript中,我认为以下是等价的:

a['title'] = "Syntactic sugar is good for yr teeth.";
a.title = "Syntactic sugar is good for yr teeth.";