
PHP中define和defined的区别
对于初学者会混淆这两个函数
1.define用来定义一个常量,常量也是全局范围的。不用管作用域就可以在脚本的任何地方访问
常量。一个常量一旦被定义,就不能再改变或者取消定义
如: define("path","mlx1036@163.com") define为常mlx1036@163.com
为常量的值
2.defined用来检测常量有没有被定义,若常量存在,则返回 true,否则返回 false如:
if(defined("path")){
echo "true";
}else{
echo "false";
}
3.isset()判断一个变量是否定义
if (isset($var)) {
print "This var is set set so I will print.";
}
4.function_exists判断一个函数是否定义
if(function_exists('date_default_timezone_set'))//检查函数是否定义
{
date_default_timezone_set("Asia/Chongqing");
}
5.file_exists判断一个文件是否存在
<?php
$file = '/www/index.php';
if (file_exists($file)) {
echo "$file";
} else {
echo "false";
}
?>