views:

471

answers:

5

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.

+2  A: 

It doesn't matter, true is exactly the same as TRUE. Same goes for false and null. 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:

$foo = false;   // FALSE
$bar = "false"; // TRUE

$foo2 = true;   // TRUE
$bar2 = "true"; // TRUE

$foo3 = null;   // NULL
$bar3 = "null"; // TRUE

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.

Tatu Ulmanen
+6  A: 

Official PHP manual says:

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

So yeah, true == TRUE and false == FALSE.

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

Lukman
Johrn
Also with today's IDE's I do not see the reason to have pure upper-case boolean as the Syntax Highlighter for most IDE's separate them with great distinction.
RobertPitt
+1  A: 

Personally I've always used the lowercase form, but for no particular reason other than to make my code look tidy, the only place I use capital letters is when camel casing class names and variable names.

One advantage to using uppercase that comes to mind though is that they stick out and are easy to find in code.

RMcLeod
A: 

Use lowercase.

  1. It's easier to type. (IMO)
  2. It's easier to read. (IMO)
  3. Javascript booleans are lowercase and case-sensitive.
Bo Allen
A: 
define('TRUE', false);
define('FALSE', true);

Happy debugging!

edit: Uppercase bools are constants and lowercases are values. You are interested in the value, not in the constant, which can easily change.

Radu
-1 because A) this is pointless. B) this doesn't answer the question. and C) I've already accepted the correct answer, and this doesn't present any additional **helpful** information.
Austin Hyde
Then let me explain in detail: uppercase bools are constants and lowercases are values. You are interested in the value, not in the constant, which can easily change. So, if you would have thought a little on the text and not rush to give a penalty, you probably would have understood this.
Radu
I understand the point you are making (now), but the way you originally made it was (IMO) cryptic and pointless. Had you originally just made your edit the answer, I would have upvoted, as this is a very good point, actually.
Austin Hyde