刚刚发现我的代码中有一个原始拼写错误.
$msg = "Some text";
$msg .= " some more text";
$msg .+ " yet more text!";
$msg .= " last text";
Run Code Online (Sandbox Code Playgroud)
注意.+那应该是.=.让我感到惊讶的是,代码运行时没有产生任何错误,警告或通知,输出结果是:
Some text some more text last text
我想知道它为什么这样做.我清楚地知道什么.=和+=有但是如何.+解释特别是因为没有等号.
Lig*_*ica 10
没有.+操作员,所以.接下来是+.
你正在构建包括表达$msg与应用一元的结果串接+到" yet more text!"(这是0由于铸造到整数)...然后丢弃整个事情,因为你不这样做,结果什么.
$msg .+ " yet more text!";
$msg . +" yet more text!"; // 1. PHP doesn't care about the spacing
$msg . 0; // 2. Conversion to int from unary `+`
$msg . "0"; // 3. Coersion to string for concatenation
// 4. Nothing done with value
Run Code Online (Sandbox Code Playgroud)
这完全有效; 它只是没有做任何有用的事情.