首页 » 网站建设 » php断定有无文件技巧_php判断文件目录函数类方法变量是否存在

php断定有无文件技巧_php判断文件目录函数类方法变量是否存在

访客 2024-12-14 0

扫一扫用手机浏览

文章目录 [+]

目录是否存在:is_dir;

例子:

php断定有无文件技巧_php判断文件目录函数类方法变量是否存在

$dir='./data';

php断定有无文件技巧_php判断文件目录函数类方法变量是否存在
(图片来自网络侵删)

if(is_dir($dir)) echo \"大众目录\公众.$dir.\"大众存在\公众; else echo \公众目录\"大众.$dir.\"大众不存在\"大众;

类,类方法,普通方法函数

类是否存在:class_exists('calss');

类里面的某个方法是否存在:method_exists ($class,'method');

系统函数或自己写的函数是否存在:function_exists('function');

例子:

class main{

function index(){

echo '我是类里的index方法';

}

}

function index(){

echo '我是index方法';

}

if(class_exists('main')) $main=new main();

if(method_exists($main,'index')) $main->index();//我是类里的index方法

if(function_exists('index')) index(); else echo '没有index方法'; //我是index方法

变量

变量是否存在:isset() 、empty()与is_null

isset()在变量不存在或者为null时,判断为false;

empty()在变量不存在和$x=''/null/array()/false/0/'0',判断为true

is_null()与isset相反

标签:

相关文章