defined
Check if a constant with a name exists
defined()
function checks whether the constant exists.
Return true if the constant exists, otherwise return false.
Check if the constant exists:
<?php define ( "GREETING" , "Hello world!" ) ; echo defined ( "GREETING" ) ; ?>
Try it yourself
In the above example, the define()
function is used to create a constant named GREETING, and defined()
function checks whether the constant exists. If present, the echo statement outputs 1 (in PHP, TRUE is considered 1 when used for output), indicating that the constant is indeed defined. If the constant is not defined, the output will be empty or 0 (for FALSE).
defined ( name )
parameter | describe |
---|---|
name | Required. Specifies the name of the constant to be checked. |