Uppercase Booleans vs. Lowercase in PHP
define('TRUE', false);
define('FALSE', true);
Happy debugging! (PHP < 5.1.3 (2 May 2006), see Demo)
Edit: Uppercase bools are constants and lowercases are values. You are interested in the value, not in the constant, which can easily change.
Eliminated run-time constant fetching for TRUE, FALSE and NULL author dmitry <dmitry> Wed, 15 Mar 2006 09:04:48 +0000 (09:04 +0000) committer dmitry <dmitry> Wed, 15 Mar 2006 09:04:48 +0000 (09:04 +0000) commit d51599dfcd3282049c7a91809bb83f665af23b69 tree 05b23b2f97cf59422ff71cc6a093e174dbdecbd3 parent a623645b6fd66c14f401bb2c9e4a302d767800fd
Commits d51599dfcd3282049c7a91809bb83f665af23b69 (and 6f76b17079a709415195a7c27607cd52d039d7c3)
The 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 reasons. It's the same reason for my preference on using OR
over or
or ||
, and on using AND
over and
or &&
.
The PSR-2 standard requires true
, false
and null
to be in lower case.
If you intend to use JSON, then RFC7159 says:
The literal names MUST be lowercase. No other literal names are allowed.
From the list of backward incompatible changes in PHP 5.6:
json_decode() now rejects non-lowercase variants of the JSON literals true, false and null at all times, as per the JSON specification
According to PSR-2 standard:
PHP keywords MUST be in lower case.
The PHP constants true, false, and null MUST be in lower case.
Use lowercase.
- It's easier to type. (IMO)
- It's easier to read. (IMO)
- JavaScript booleans are lowercase and case-sensitive.