Tuesday, June 27, 2006

 

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.

5 Comments:

Blogger Sined said...

Thanks you so much for all these tips.
I'm a french guy and I like your website.

2:59 PM 
Blogger Sined said...

Is that the same thing for “NULL” and “null”?
Thanks

9:49 AM 
Blogger Denis said...

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)
{
}

4:03 AM 
Blogger Dazza said...

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.

4:09 PM 
Blogger Kashub said...

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)

2:21 AM 

Post a Comment

Links to this post:

Create a Link

<< Home