Is there a difference between true
and TRUE
or false
and FALSE
in PHP?
Edit: Uppercase bools are constants and lowercases are values. You are interested in the value, not in the constant, which can easily change.
They are not case-sensitive, but the general consensus among PHP coders is to use all upper-case. It's more of a stylistic preference than an actual syntax rule.
A Boolean represents two possible states: TRUE or FALSE. $x = true; $y = false; Booleans are often used in conditional testing.
Value 0 and 1 is equal to false and true in php.
If you intend to use JSON then the standard RFC7159 says :
The literal names MUST be lowercase. No other literal names are allowed.
And from 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
And according to PSR-2 standard :
PHP keywords MUST be in lower case.
The PHP constants true, false, and null MUST be in lower case.
Ps.: I could not post link to the RFC7159 because of SO limitations.
Constants are case-sensitive per default. But for symmetry to the other identifier namespaces, they can be defined case-insensitively:
define("mixedCASE", 123, TRUE);
print MiXeDcAsE;
And that's just how TRUE
and FALSE
were pre-declared. (They aren't parser/language builtins.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With