PHP中的大写布尔与小写 [英] Uppercase Booleans vs. Lowercase in PHP

查看:159
本文介绍了PHP中的大写布尔与小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学习PHP时,我读到某个地方应该始终使用布尔值的大写版本TRUEFALSE,因为没有普通"的小写版本truefalse. t使用安全".

When I was learning PHP, I read somewhere that you should always use the upper case versions of booleans, TRUE and FALSE, because the "normal" lowercase versions, true and false, weren't "safe" to use.

已经有很多年了,我编写的每个PHP脚本都使用大写版本.但是,现在,我对此提出了质疑,因为我已经看到很多用小写版本(即Zend Framework)编写的PHP.

It's now been many years, and every PHP script I've written uses the uppercase version. Now, though, I am questioning that, as I have seen plenty of PHP written with the lowercase version (i.e. Zend Framework).

是否/曾经有理由使用大写版本,还是完全可以使用小写?

Is/Was there ever a reason to use the uppercase version, or is it perfectly OK to use the lowercase?

忘了说这也适用于NULLnull.

推荐答案

官方PHP手册说:

要指定布尔文字,请使用 关键字TRUE或FALSE.两者都是 不区分大小写.

To specify a boolean literal, use the keywords TRUE or FALSE. Both are case-insensitive.

是的,true === TRUEfalse === FALSE.

但是,出于可读性的考虑,个人而言,我更喜欢TRUE而不是true以及FALSE而不是false.这也是我偏爱在or||上使用OR以及在and&&上使用AND的相同原因.

Personally, however, I prefer TRUE over true and FALSE over false for readability reasons. It's the same reason for my preference on using OR over or or ||, and on using AND over and or &&.

PSR-2 标准要求truefalsenull小写.

这篇关于PHP中的大写布尔与小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆