Boolean data type
PHP is allowing to write Boolean data type with uppercase or lowercase. But, writing with lowercase is more faster than uppercase. When found a constant, PHP do lookup hash constant name.
if ($var = TRUE) {
...
}
//this is more faster
if ($var = true) {
...
}
When using a Boolean value, 1 and 0 are more faster than true and false.
if ($var = TRUE) {
...
}
//this is more faster
if ($var = true) {
...
}
When using a Boolean value, 1 and 0 are more faster than true and false.




5 Comments:
Thanks you so much for all these tips.
I'm a french guy and I like your website.
Is that the same thing for “NULL” and “null”?
Thanks
Just a note - that check is awful.
First of all, it's "==", not "=".
Secondly, you do not compare a value to "true", you just check it like this:
if ($var)
{
}
I agree with Denis there completely. When checking boolean variables you should just keep it simple
if($boolean){
}
OR
if(!$boolean){
}
This is the best way to go about it. Also with 'more faster' doesn't make sense, 'faster' does.
It's always true:
if ($var = true)
You must use:
if ($var == true)
Good practice is writing in this way:
if (true == $var)
you can avoid mistakes like in this post, because it will cause some error when trying:
if (true = $var)
Post a Comment
Links to this post:
Create a Link
<< Home