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.