当插值PHP的字符串索引数组元素(5.3.3,Win32)时,可能会出现以下现象:
$ha = array('key1' => 'Hello to me');
print $ha['key1']; # correct (usual way)
print $ha[key1]; # Warning, works (use of undefined constant)
print "He said {$ha['key1']}"; # correct (usual way)
print "He said {$ha[key1]}"; # Warning, works (use of undefined constant)
print "He said $ha['key1']"; # Error, unexpected T_ENCAPSED_AND_WHITESPACE
print "He said $ha[ key1 ]"; # Error, unexpected T_ENCAPSED_AND_WHITESPACE
print "He said $ha[key1]"; # !! correct (How Comes?)
毫无疑问,最后一行似乎是正确的PHP代码。有什么解释吗?可以信任此功能吗?
编辑:现在发布的要点以黑体显示,以减少误解。
繁华开满天机
阿波罗的战车