Home  >  Article  >  Backend Development  >  print 无括号常量参数的疑问

print 无括号常量参数的疑问

WBOY
WBOYOriginal
2016-06-06 20:40:131135browse

$a=1;$b=2;
print $a,PHP_EOL,$b,PHP_EOL;
echo $a,PHP_EOL,$b,PHP_EOL;

官方说文文档里面说两者都支持逗号分隔的参数列表.但是遇到这种常量参数的情况下print会报错,echo 不会。
这算不算一个bug?

回复内容:

$a=1;$b=2;
print $a,PHP_EOL,$b,PHP_EOL;
echo $a,PHP_EOL,$b,PHP_EOL;

官方说文文档里面说两者都支持逗号分隔的参数列表.但是遇到这种常量参数的情况下print会报错,echo 不会。
这算不算一个bug?

楼主没有仔细看文档把, print, echo 都不是一个函数, 是一个语言结构, 所以可以省略括号,
但是 print 方法只接受一个参数, 而 echo 方法接受可变参数.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn