导航首页 » 技术教程 » PHP:defined()的用法_misc函数
PHP:defined()的用法_misc函数 147 2023-12-15   

defined

(PHP 4, PHP 5)

defined — 检查某个名称的常量是否存在

说明

bool defined ( string $name )

检查该名称的常量是否已定义。

Note:

如果你要检查一个变量是否存在,请使用 isset()。 defined() 函数仅对 constants 有效。如果你要检测一个函数是否存在,使用 function_exists()。

参数

name

常量的名称。

返回值

如果该名称的常量已定义,返回 TRUE;未定义则返回 FALSE

范例

Example #1 检查常量

<?php
/* Note the use of quotes, this is important.  This example is checking
 * if the string 'TEST' is the name of a constant named TEST */
if (defined('TEST')) {
    echo TEST;
}
?>

参见

define() - 定义一个常量 constant() - 返回一个常量的值 get_defined_constants() - 返回所有常量的关联数组,键是常量名,值是常量值 function_exists() - 如果给定的函数已经被定义就返回 TRUE Constants这一节


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103