NETTİM
← Kod Sonuçlarına Dön
PHP Fonksiyonlar Görsel işlemleri Lisans: Belirtilmemis

PHP: Constants - Manual

PHP: Constants - Manual • PHP — Fonksiyonlar, Görsel işlemleri. Fonksiyonlar: foo.
/manual/en/language.constants.php • PHP
The documentation says, "You can access constants anywhere in your script without regard to scope", but it's worth keeping in mind that a const declaration must appear in the source file before the place where it's used.

This doesn't work (using PHP 5.4):
<?php
foo();
const X = 1;
function foo() {
    echo "Value of X: " . X;
}
?>
Result: "Value of X: X"

But this works:
<?php
const X = 1;
foo();
function foo() {
    echo "Value of X: " . X;
}
?>
Result: "Value of X: 1"

This is potentially confusing because you can refer to a function that occurs later in your source file, but not a constant. Even though the const declaration is processed at compile time, it behaves a bit like it's being processed at run time.

Benzer Kod Örnekleri

PHP: Constants - Manual
PHP • Fonksiyonlar
PHP: Introduction - Manual
PHP • Fonksiyonlar
PHP (Bootstrap) — bootstrap.php
PHP • Bootstrap • Fonksiyonlar
PHP — .php-cs-fixer.php
PHP • Ağ işlemleri