Copy codeThe Code is as follows:
If (defined ('const _ name ')){
// Do something
}
Isset is used for variable detection. Note that if the variable is not declared or declared, the value is NULL, and isset returns FALSE, for example:
Copy codeThe Code is as follows:
If (isset ($ var_name )){
// Do something
}
Function_exists is used for function detection. You must use quotation marks for the function name to be detected, for example:
Copy codeThe Code is as follows:
If (function_exists ('fun _ name ')){
Fun_name ();
}
Let's look at an instance.
Copy codeThe Code is as follows:
<? Php
/* Determine whether a constant exists */
If (defined ('myconstant ')){
Echo MYCONSTANT;
}
// Determine whether a variable exists
If (isset ($ myvar )){
Echo "variable $ myvar .";
}
// Determine whether a function exists
If (function_exists ('imap _ open ')){
Echo "The imag_openn function exists ";
} Else {
Echo "The imag_open function does not exist n ";
}
?>
Function_exists
Copy codeThe Code is as follows:
<? Php
If (function_exists ('test _ func ')){
Echo "The test_func function exists ";
} Else {
Echo "The test_func function does not exist ";
}
?>
Filter_has_var Function
The filter_has_var () function checks whether a variable of the specified input type exists.
If yes, true is returned. Otherwise, false is returned.
Copy codeThe Code is as follows:
<? Php
If (! Filter_has_var (INPUT_GET, "name "))
{
Echo ("Input type does not exist ");
}
Else
{
Echo ("Input type exists ");
}
?>
Output is. Input type exists