NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - constant

Trieda

Koreň \ Bez triedy

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ázovDátový typPredvolená hodnotaPopis
$namestring

The constant name. It must be written in apostrophes/qu­otation 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

Súvisiace manuály

      • function define (string $name, mixed $value, bool $case_insensitive = false) : bool
      • function defined (string $name) : bool
      Aktivity