判断系统函数或自己写的函数是否存在
bool function_exists(string $function_name)
if(function_exists('curl_init')) {
curl_init();
} else {
echo 'not function curl_init';
}
判断类是否存在
bool class_exists(string $class_name [, bool $autoload = true])
if(class_exists('MySQL')) {
$myclass=new MySQL();
}
判断类的属性是否存在
bool property_exists(mixed $class,string $property)
$directory=new Directory;
if(!property_exists($directory,'li')){
echo '未定义li属性!';
}
判断类的方法是否存在
bool method_exists(mixed $object, string $method_name)
$directory=new Directory;
if(!method_exists($directory,'read')) {
echo '未定义read方法!';
}
判断数组中的key是否存在
isset()
$arr = ['aaa' => 'bbb']
if(isset($arr['aaa'])) {
echo '存在aaa角标';
}
array_key_exists($key, $array)
$arr = ['aaa' => 'bbb']
if(array_key_exists('aaa', $arr)) {
echo '存在aaa角标';
}