输出结果及解释
1
heimonsy Dec 5, 2014
会解析成
echo '1' . print 3 + 2 参考php手册: http://php.net/manual/zh/function.print.php print 实际上不是一个函数(它是一个语言结构),因此你可以不必使用圆括号来括起它的参数列表 |
2
Paranoid Dec 5, 2014
这种就是抖机灵
会用在工程中么? |
3
leiliang Dec 5, 2014
要看php引擎是怎么编译的以及对数据类型怎么转换的,这种东西,不深入到底层还真是说不清楚
|
4
vibbow Dec 6, 2014
运行结果居然是511?!
|
5
gDD Dec 6, 2014 参考 @heimonsy 的链接,里面有这个一句:But since the parenthesis around the argument are not required, they are interpretet as part of the argument.
也就是说,在这里[echo '1'.print(3)+2],print 后面的都被作为了 print 的参数,所以会被解析成 echo '1' . (print 3 + 2) 首先 print 部分被执行了,输出5 由于print永远会返回1,这个1与字符串‘1’相加(.),成为了字符串‘11’ 这个字符串‘11‘被echo出来 就是 @vibbow 的结果,显示为’511‘。 |
6
yinxingren Dec 6, 2014 via Android
|