Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php - TRUE or true difference? [duplicate]

Tags:

php

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?

like image 339
mahen3d Avatar asked Jul 18 '12 10:07

mahen3d


2 Answers

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.

like image 176
Diego Agulló Avatar answered Nov 19 '22 05:11

Diego Agulló


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

like image 33
Baptiste Placé Avatar answered Nov 19 '22 03:11

Baptiste Placé