英文:
If you want to see if a variable exists, use isset() as defined() only applies to constants. If you want to see if a function exists, use function_exists().
翻译:
<?php
/* 判断常量是否存在*/
if (defined('CONSTANT1')) {
echo CONSTANT1;
}
//判断变量是否存在
if (isset($myvar)) {
echo "$myvar.";
}
//判断函数是否存在
if (function_exists('open')) {
echo "存在函数open/n";
} else {
echo "函数open不存在/n";
}
?>
本文介绍了如何使用PHP内置函数来检查常量、变量及函数是否存在的方法。通过使用defined(), isset() 和 function_exists() 函数,可以有效地进行运行时的安全性检查。

被折叠的 条评论
为什么被折叠?



