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.
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?
edit: Forgot to mention that this applies to NULL
and null
as well.
I've written simple code to check the differences between false and FALSE: Each iteration was doing something that:
Here are the results:
So we can see that performance is very slightly touched by the booleans case - lowercase is faster. But certainly you won't see.
The official PHP manual says:
So yeah,
true === TRUE
andfalse === FALSE
.Personally, however, I prefer
TRUE
overtrue
andFALSE
overfalse
for readability reasons. It's the same reason for my preference on usingOR
overor
or||
, and on usingAND
overand
or&&
.The PSR-2 standard requires
true
,false
andnull
to be in lower case.Here is my TEST on Windows 7x64bit Apache/2.4.9 PHP/5.5.14
This time FALSE won 20 times. So uppercase is faster in my environment.
I used to do C style TRUE/FALSE booleans like all consts, in all caps, until I got on the PSR bandwagon.
Section 2.5 of PSR-2:
So basically, if you want to play nice with open source style particulars, Booleans gotta be lower case.
It doesn't matter,
true
is exactly the same asTRUE
. Same goes forfalse
andnull
. I haven't heard that it would have mattered at any point.The only way you can mess things up is by quoting those values, for example:
Only thing restricting or encouraging you to use upper or lowercase might be your company's or your own coding guidelines. Other than that, you're free to use either one and it will not lead in any issues.
Use lowercase.