Is undefined a data-type in php?
Also, how does one check for it (on a variable, is or is not undefined)?
Is undefined a data-type in php? Also, how does one check for it (on
Share
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.
There is no “undefined” data type in PHP. You can check for a variable being set with
isset, but this cannot distinguish between a variable not being set at all and it having anullvalue:However, there is a trick you can use with
compactthat allows you to determine if a variable has been defined, even if its value isnull:Live example.
Both
issetand thecompacttrick also work for multiple variables at once (use a comma-separated list).You can easily distinguish between a
nullvalue and total absence when dealing with array keys:Live example.
When dealing with object properties there is also
property_exists, which is the equivalent ofarray_key_existsfor objects.