define()
define() — Defines a named constant.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
Signature
define(string $constant_name, mixed $value, bool $case_insensitive = false): bool
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $constant_name | string | The name of the constant. |
| $value | mixed | The value of the constant. |
| $case_insensitive | bool | If set to true, the constant will be defined case-insensitive. The default behavior is case-sensitive; i.e. CONSTANT and Constant represent different values. |
Return value
Returns true on success or false on failure.
Example
A runnable snippet:
define("CONSTANT", "Hello world."); echo CONSTANT; // outputs "Hello world." echo Constant; // outputs "Constant" and issues a notice. define("GREETING", "Hello you.", true); echo GREETING; // outputs "Hello you." echo Greeting; // outputs "Hello you." // Works as of PHP 7 define('ANIMALS', array( 'dog', 'cat', 'bird' )); echo ANIMALS[1]; // outputs "cat"
Changelog
| Version | Change |
|---|---|
| 8.1.0 | value can now be an object. |
| 8.0.0 | Passing true to case_insensitive now emits an E_WARNING. Passing false is still allowed. |
| 7.3.0 | case_insensitive has been deprecated and will be removed in version 8.0.0. |
See also
All PHP 8.5 built-in functions
Reference card built from the PHP manual page define() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.