douqi0090 2013-06-29 15:11
浏览 19
已采纳

使用括号时,打印构造的行为是否有所不同?

I am not sure if parentheses make difference or I am doing something wrong! Here is a situation I accidentally encountered..

 print (FALSE or TRUE);     //prints '1'
 print FALSE or TRUE;       //prints nothing

We know that FALSE or TRUE evaluates to TRUE, but surprisingly, printing TRUE is not affected by parentheses!

  print (TRUE);     //prints '1'
  print TRUE;       //prints '1'

The manual mentions clearly that using parentheses is not required! Here is a quote from the manual..

print is not actually a real function (it is a language construct) so you are not required to use parentheses with its argument list.

What I want to know ..

  • Is it a bug?
  • If it is not a bug, how do parentheses affect the output?
  • Which way gives expected output, using parentheses or omitting them?

I am using PHP Version 5.4.7 on Windows 8.

Thanks!

  • 写回答

2条回答 默认 最新

  • doulu7921 2013-06-29 15:19
    关注
    print (FALSE or TRUE);     //prints '1'
    

    evaluates FALSE or TRUE (which gives TRUE), and then prints the result of that evaluation

    print FALSE or TRUE;       //prints nothing
    

    prints FALSE (which is displayed as an empty string); and if that fails (or) then does nothing with TRUE

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题