1

Possible Duplicate:
How do the equality (== double equals) and identity (=== triple equals) comparison operators differ?

if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL) === 0)

or

if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL) == 0)

Should I use == or === here?

Where can I use ===?

Community
  • 1
  • 1
makcbn
  • 19
  • 3

3 Answers3

1

=== is used to make a strict comparison, that is, compare if the values are equal and of the same type.

Look at @Ergec's answer for an example.


In your case you should do just:

if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL) == false)

or simply

if (filter_input(INPUT_GET, "email", FILTER_VALIDATE_EMAIL))

because filter_input() returns:

Value of the requested variable on success, FALSE if the filter fails, or NULL if the variable_name variable is not set. If the flag FILTER_NULL_ON_FAILURE is used, it returns FALSE if the variable is not set and NULL if the filter fails.

Shef
  • 41,793
  • 15
  • 74
  • 88
0

In PHP double equals matches only VALUE

if (2 == "2") this returns TRUE

Triple equals matches VALUE AND TYPE

if (2 === "2") this returns FALSE
Ergec
  • 10,718
  • 7
  • 48
  • 59
0

You are looking for !== FALSE in that case.

filter_input will either return the filtered variable or FALSE.

=== checks if both sides are equal and of the same type.

!== checks if both sides are not equal and of the same type.

Cobra_Fast
  • 14,395
  • 8
  • 51
  • 97
  • Caution: if `!== FALSE` is used, the filter will pass if the variable is not set. – Shef Jul 13 '11 at 13:34
  • About "*`!==` checks if both sides are **not** equal and of the same type.*" phrase - it should be written as "*`!==` checks if both sides are **not** equal **or** of the same type.*" – binaryLV Jul 13 '11 at 13:45
  • @binaryLV it's correct the way I wrote it. – Cobra_Fast Jul 15 '11 at 09:11