Current Location: Home> Function Categories> defined

defined

Check if a constant with a name exists
Name:defined
Category:Miscellaneous
Programming Language:php
One-line Description:Check if the constant exists.

Definition and usage

defined() function checks whether the constant exists.

Return true if the constant exists, otherwise return false.

Example

Check if the constant exists:

 <?php
define ( "GREETING" , "Hello world!" ) ;
echo defined ( "GREETING" ) ;
?>

Try it yourself

Example explanation:

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).

grammar

 defined ( name )
parameter describe
name Required. Specifies the name of the constant to be checked.
Similar Functions