Home > Article > Backend Development > php check if variable exists
PHP Determines whether constants, variables and functions exist
Determines whether variables are defined: defined()
1 if (defined('CONST_NAME')) { 2 //do something 3 }
Determine whether the variable exists: isset(). Note that the variable is not declared or is assigned a value of NULL when declared. isset returns FALSE, such as:
1 if (isset($var_name)) { 2 //do something 3 }
Function detection Use function_exists, note that the function name to be detected also needs to use quotation marks, such as:
1 if (function_exists('fun_name')) { 2 fun_name(); 3 }
Example:
function_exists determines whether the function exists
1
filter_has_var function
filter_has_var() function checks whether a variable of the specified input type exists.
If successful, return true, otherwise return false.
1
Recommended tutorial: PHP video tutorial
The above is the detailed content of php check if variable exists. For more information, please follow other related articles on the PHP Chinese website!