[nycphp-talk] Need help understanding NULL

John Campbell jcampbell1 at
Sat Aug 29 22:00:45 EDT 2009

You should be aware that PHP and SQL have completely different concepts of null.

In php, null is a unique magic value that means "undefined", and if
two things are null, then they are equal.

var_dump($a===$b) // bool(true)
var_dump(NULL === NULL) // bool(true)

Contrast this with SQL, where null is akin to "not yet known value"

| NULL |
In a SQL view of the world, that can be interpreted as:
Are two not yet known values equal?
and the answer is:
"Not yet known"

In sql, every comparison to NULL, yields another NULL.
That is why 'SELECT * WHERE foo = NULL' doesn't do what you might
expect.  In fact that query is guaranteed to always return zero rows.

It is a fact of life that pretty much every language handles NULL
differently, and whenever I learn a new language, it is one of the
first things I research.

John Campbell

More information about the talk mailing list