PHP const Keyword

PHP Keywords : Create a constant and print its value

Definition and Usage

The const keyword is used to create constants. Unlike with the define() function, constants created using the const keyword must be declared in the global scope.

Related Pages

Read more about constants in our PHP Constants Tutorial.

More Examples

Example

Create a constant and print its value:

<?php
class MyClass {
  const MY_CONSTANT = 5;
}

echo MyClass::MY_CONSTANT;
?>

❮ PHP Keywords