define

Defines a named constant

Syntax

define(string $constant_name, mixed $value): bool

Parameters

constant_name

The name of the constant.

Note: It is possible to define() constants with reserved or even invalid names, whose value can (only) be retrieved with constant(). However, doing so is not recommended.

value

The value of the constant.

Warning: While it is possible to define resource constants, it is not recommended and may cause unpredictable behavior.

Return

Returns TRUE on success or FALSE on failure.

Examples

constant_name value | null

<?

define("MYCONSTANT", null);

var_export(MYCONSTANT);

?>
NULL

constant_name value | boolean

<?

define("MYCONSTANT", true);

var_export(MYCONSTANT);

?>
true

constant_name value | float

<?

define("MYCONSTANT", 0.1);

echo MYCONSTANT;

?>
0.1

constant_name value | integer

<?

define("MYCONSTANT", 1);

echo MYCONSTANT;

?>
1

constant_name value | string

<?

define("MYCONSTANT", "Hello World!");

echo MYCONSTANT;

?>
Hello World!

constant_name value | array

<?

define("MYCONSTANT", array(0, 1));

print_r(MYCONSTANT);

?>
Array
(
    [0] => 0
    [1] => 1
)

Return

<?

$return = define("MYCONSTANT", array(0, 1));

var_export($return);

?>
true

PHP

Home Menu