判断函数是否存在

当我们创建了自定义函数,并且了解了可变函数的用法,为了确保程序调用的函数是存在的,经常会先使用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.'; }
原文地址:https://www.cnblogs.com/shark1100913/p/5568347.html