判断函数是否存在
当我们创建了自定义函数,并且了解了可变函数的用法,为了确保程序调用的函数是存在的,经常会先使用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
总结
- 上一篇: CXF之webservice
- 下一篇: 【剑仙教程】易语言的结构体。自定义数据类