Constant detection uses defined, and defining constants is define. Note the constants to be detected need to use quotation marks (single and double), such as:
The code is as follows
if (defined (' Const_name ')) {
Do something
}
Variable detection is the use of isset, note that variables are not declared or declared when the assignment value is Null,isset return false, such as:
The code is as follows
if (Isset ($var _name)) {
Do something
}
function detection with function_exists, note that the function name to be detected also needs to use quotation marks, such as:
if (function_exists (' Fun_name ')) {
Fun_name ();
}
Let's just say we're going to see an example.
The code is as follows
/* Determine if constant exists */
if (defined (' myconstant ')) {
Echo myconstant;
}
Determine if a variable exists
if (Isset ($myvar)) {
echo "existence variable $myvar.";
}
Determine if a function exists
if (function_exists (' Imap_open ')) {
echo "existence function Imag_openn";
} else {
echo "function Imag_open does not exist n";
}
?>
Function_exists determine if a function exists
The code is as follows
if (function_exists (' Test_func ')) {
echo "function Test_func exists";
} else {
echo "function Test_func does not exist";
}
?>
Filter_has_var function
The Filter_has_var () function checks for the existence of a variable of the specified input type.
Returns true if successful, otherwise false is returned.
The code is as follows
if (!filter_has_var (Input_get, "name"))
{
Echo ("Input type does not exist");
}
Else
{
Echo ("Input type exists");
}
?>
Output is. Input type exists
http://www.bkjia.com/PHPjc/371412.html www.bkjia.com true http://www.bkjia.com/PHPjc/371412.html techarticle constant detection uses defined, and defining constants is define. Note the constants to be detected need to use quotation marks (single and double), such as: code as follows if (defined (' Const_name ')) {//do somethin ...