If you want to test whether a variable is really NULL
, use the identity operator:
$user_id === NULL // FALSE == NULL is true, FALSE === NULL is false
is_null($user_id)
If you want to check whether a variable is not set:
!isset($user_id)
Or if the variable is not set or has an "empty" value (an empty string, zero, etc., see this page for the full list):
empty($user_id)
If you want to test whether an existing variable contains a value that's considered "not empty" (non-empty string or array, non-zero number, etc..), !
will be sufficient:
!$user_id