2

Possible Duplicate:
Null vs. False vs. 0
How does php cast boolean variables?

I know that some values will return true for $value == NULL and not for $value === NULL but is there a complete list of these values?

Also, is isset($value) equivalent to $value === NULL and empty($value) equivalent to $value == NULL?

Community
  • 1
  • 1
CLo
  • 3,650
  • 3
  • 26
  • 44
  • 2
    Maybe this will answer you http://php.net/manual/en/types.comparisons.php – nikc.org Dec 20 '11 at 15:51
  • The only time when `$value === NULL` is true, is when `$value = NULL`, or it isn't defined. – BoltClock Dec 20 '11 at 15:51
  • Neither of the Duplicate questions address types other than boolean or integer. For example array() == NULL vs. array() !== NULL. I was looking for a more complete list than those provided. – CLo Dec 20 '11 at 16:06

5 Answers5

3

http://www.php.net/manual/en/types.comparisons.php

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
1

NULL === NULL

Nothing else does. So if a function returns NULL then checking with === will return true.

Also, is isset($value) equivalent to $value === NULL and empty($value) equivalent to $value == NULL?

No, not strictly. Those two are "language constructs" and not functions. They only accept variable names, isset accepts multiple parameters, and warnings are relaxed when using unset variables.

Matthew
  • 47,584
  • 11
  • 86
  • 98
0

The purpose of the triple equals is to ensure the types match as well. Using only ==, PHP performs truthy/falsy logic, meaning 0==null, 0=='', null=='' are all true, but 0===null, 0==='', null==='' are all false.

Also, '90210'==90210 is true, but '90210'===90210 is false.

Matthew
  • 24,703
  • 9
  • 76
  • 110
0

I suggest you these readings:

About NULL: http://php.net/manual/en/language.types.null.php
About empty(): http://php.net/manual/en/function.empty.php (you are wrong about it!)
About isset(): http://php.net/manual/en/function.isset.php

From the offical documentation, they are very explanatory.

lorenzo-s
  • 16,603
  • 15
  • 54
  • 86
0

Anything that evaluates to FALSE when converted to a boolean is == NULL.

So that would be:

  (bool) FALSE
   (int) 0
 (float) 0.0
(string) '' // an empty string
(string) '0'
 (array) array()
 // An object with zero member variables (PHP 4 only)
 // SimpleXML objects created from empty tags

And, obviously, NULL itself. But only NULL and variables with no value are === NULL.

This may help clarify some things.

DaveRandom
  • 87,921
  • 11
  • 154
  • 174