Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are PHP booleans both lower case and upper case?

Is there a difference between true and TRUE or false and FALSE in PHP?

like image 416
Roman Avatar asked Dec 22 '11 02:12

Roman


People also ask

Are booleans capitalized 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.

Is PHP boolean case sensitive?

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.

What is Boolean data type in PHP?

A Boolean represents two possible states: TRUE or FALSE. $x = true; $y = false; Booleans are often used in conditional testing.

Is 1 true in PHP?

Value 0 and 1 is equal to false and true in php.


2 Answers

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.

like image 81
Mandrake Avatar answered Nov 12 '22 10:11

Mandrake


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.)

like image 40
mario Avatar answered Nov 12 '22 08:11

mario