I also get confused how to check if a variable is false/null when returned from a function.
When to use empty() and when to use isset() to check the condition ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For returns from functions, you use neither
issetnorempty, since those only work on variables and are simply there to test for possibly non-existing variables without triggering errors.For function returns checking for the existence of variables is pointless, so just do:
To read about this in more detail, see The Definitive Guide To PHP’s
issetAndempty.