PHP - constant
Trieda
Metóda - constant
(PHP 4 >= 4.0.4, PHP 5, PHP 7)
The constant() function returns the value of a constant by its
name. It also works with class constants.
If the constant is not defined, the function emits a warning.
Procedurálne
- function constant (string $name) : mixed
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $name | string | The constant name. It must be written in apostrophes/quotation marks. |
Mávratovej hodnoty
Vracia: mixed
Returns the value of a constant, or null if the constant is not
defined.
Príklady
<?php
define('CONSTANT', 'text');
echo CONSTANT;
echo '<br />';
echo constant('CONSTANT');
echo '<br />';
class Test {
const CLASS_CONSTANT = 100;
}
echo constant('Test::CLASS_CONSTANT');
echo '<br />';
var_dump(constant('CLASS_CONSTANT')); // Throws a warning and outputs NULL
