0

Can I use functions like is_integer(), is_string(), and other like them as a reliable check to see if the variable is null? I guess what I am asking is if the variable is null with they all return false?

1
  • Well, if the variable is null you can conclude that is_string() gives you false. But if is_string() gives you false, the variable is not necessary null.... so no, you cannot use to check them whether a variable is null. Commented Apr 27, 2011 at 23:55

3 Answers 3

2

Use type comparison.

$somevar === null
Sign up to request clarification or add additional context in comments.

1 Comment

Same as with is_null(): Requires the existence of the variable (isset()).
1

You can use either is_null() or use type comparison (===). They're virtually the same, except that type comparison will be slightly faster (by slightly I mean so abysmal that it almost doesn't matter).

Comments

0

All of the is_*() functions tests the type of a value, thats theire main purpose. To test, if a variable is null, just test it ;)

is_null($var)

2 Comments

and keep in mind that is_null() means that it already passed isset()
You're right, but as far as I know thats required in any case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.