the 3"===" rather than 2 "=="
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 posted this at 16:39 — 29th October 2008.
He has: 1,502 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 posted this at 17:14 — 29th October 2008.
He has: 1,494 posts
Joined: Jun 2008
I saw some code on DZone that used
!==FALSE
and wondered if that is the proper syntax..pr0gr4mm3r posted this at 17:17 — 29th October 2008.
He has: 1,502 posts
Joined: Sep 2006
Yup, !== is the opposite of === just as != is the opposite of ==.
teammatt3 posted this at 17:56 — 29th October 2008.
He has: 2,102 posts
Joined: Sep 2003
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
decibel.places posted this at 18:15 — 29th October 2008.
He has: 1,494 posts
Joined: Jun 2008
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 posted this at 19:50 — 29th October 2008.
He has: 1,502 posts
Joined: Sep 2006
Probably because there is not negative to the assignment operator - you can't unassign something . I look at it as replacing one of the = with a ! for the not. It helps me remember it that way.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.