当咱们建立了自定义函数,而且了解了可变函数的用法,为了确保程序调用的函数是存在的,常常会先使用function_exists判断一下函数是否存在。一样的method_exists能够用来检测类的方法是否存在。函数
判断函数是否存在 function_exists()
function func() {
}
if(function_exists('func'))
{
echo"存在";
}
判断类是否存在 class_exists()
class func {
}
// 使用前检查类是否存在 if(class_exists('func')) { $func = new func(); }
判断文件是否存在
$filename = 'test.txt'; if (!file_exists($filename)) { echo $filename . ' not exists.'; }