Ezilon.com - Target Your Audience, be Seen in Your Region

the 3"===" rather than 2 "=="

You are viewing this site as a guest. Join our community to get your questions answered and share knowledge. Active members may advertise and ask for a website critique.

They have: 332 posts

Joined: Feb 2005

If i use 3 === rather than 2 == am i checking its boolean state as well as its value.

If this is true whenever i check a boolean state for instance if something is false should i do this:

if($boolean === FALSE)

does that make if($boolean == FALSE) incorrect and could result in the wrong result?

pr0gr4mm3r's picture
ModeratorSponsor

He has: 978 posts

Joined: Sep 2006

You are correct in saying === checks the type and == does not. This only means that if you do ($var == FALSE), the $var can be FALSE, 0, null, or empty string. With ($var === FALSE), $var can be only FALSE.

I hardly ever use === unless I need to test a function that might return either 0 or FALSE. strpos() is one of them.

Here are some references on php.net that further explains this:

http://us2.php.net/manual/en/language.types.boolean.php
http://us2.php.net/manual/en/language.operators.comparison.php

decibel.places's picture

They have: 917 posts

Joined: Jun 2008

I saw some code on DZone that used !==FALSE and wondered if that is the proper syntax..

pr0gr4mm3r's picture
ModeratorSponsor

He has: 978 posts

Joined: Sep 2006

Yup, !== is the opposite of === just as != is the opposite of ==.

teammatt3's picture
Moderator

He has: 1,937 posts

Joined: Sep 2003

pr0gr4mm3r wrote:

Yup, !== is the opposite of === just as != is the opposite of ==.

I wonder why the designers of these languages say == is the equality operator and != is the negation of that. != should be the negation of assignment, and !== should be the negation of equality.

It's soooo confusing Wink

decibel.places's picture

They have: 917 posts

Joined: Jun 2008

I wonder why the designers of these languages...

How about REFERER in PHP vs referrer in JavaScript?

and

var myCars = new Array("Saab","Volvo","BMW") (JavaScript (semi-colon optional))
vs
var $myCars = array("Saab","Volvo","BMW"); (PHP)

pr0gr4mm3r's picture
ModeratorSponsor

He has: 978 posts

Joined: Sep 2006

Probably because there is not negative to the assignment operator - you can't unassign something Wink. I look at it as replacing one of the = with a ! for the not. It helps me remember it that way.

Subscribe to this feed: Syndicate content