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 - defined

Trieda

Koreň \ Bez triedy

Metóda - defined

(PHP 4, PHP 5, PHP 7)

The defined() function checks whether a given constant exists and is defined. It also works with class constants.

Procedurálne

  • function defined (string $name) : bool

Parametre

NázovDátový typPredvolená hodnotaPopis
$namestring

The constant name.

Mávratovej hodnoty

Vracia: bool

Returns true if the given constant exists and is defined, otherwise returns false. The result does not depend on the constant's value.

Príklady

<?php
if (defined('CONSTANT')) {
    echo 'CONSTANT is defined';
} else {
    echo 'CONSTANT is not defined';
}
echo '<br />';

define('CONSTANT', 1);
if (defined('CONSTANT')) {
    echo 'CONSTANT is defined';
} else {
    echo 'CONSTANT is not defined';
}
echo '<br />';

define('CONSTANT_NULL', null);
if (defined('CONSTANT_NULL')) {
    echo 'CONSTANT_NULL is defined';
} else {
    echo 'CONSTANT_NULL is not defined';
}
echo '<br />';

class Test {
    const CLASS_CONSTANT = 100;
}
if (defined('Test::CLASS_CONSTANT')) {
    echo 'CLASS_CONSTANT is defined in class Test';
} else {
    echo 'CLASS_CONSTANT is not defined in class Test';
}
echo '<br />';

if (defined('CLASS_CONSTANT')) {
    echo 'CLASS_CONSTANT is defined';
} else {
    echo 'CLASS_CONSTANT is not defined';
}

Súvisiace manuály

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