34

I'm wondering, in PHP, I've seen people use both these cases:

if($var === TRUE) if($var === true) 

is there an actual difference between them or a coding standard/format to be used in boolean value?

3
  • 7
    No difference. If you want to follow the PSR-2 standard, they must be in lower case. Commented Jul 18, 2012 at 10:47
  • What about True and False? I've seen that being used and strangely the code was supposed to work, but I doubt it... Commented Nov 23, 2018 at 20:25
  • Guess, it's related with getting used to another language before becoming a PHP developer. For example in python docs, it says True and False, while in C++ you define TRUE and FALSE as constants assigned to 1 and 0 (if you don't already use stdbool.h and obey the "constants should be uppercase" rule). Commented Dec 27, 2019 at 12:00

2 Answers 2

54

There's no difference at all. From the docs:

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

According to PSR-2, as stated by both Laxus and Paul Bain in their comments, the standard is to write them in lower case.

Sign up to request clarification or add additional context in comments.

1 Comment

for Developers who will read this in 2020year :) PSR-2 is deprecated now you can read PSR-12 2.5 php-fig.org/psr/psr-12
12

lowercase is generally considered a good practice, see the coloration of the lowercase on stackoverflow :)

And not related, but you should always use true first in the condition true === $var, this is a good practice to avoid sneaky bugs when mistyping the condition, eg : $var = true

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.