PHP const Keyword

❮ PHP Keywords

Example

Create a constant and print its value:

<?php
const MY_CONSTANT = 5;
echo MY_CONSTANT;
?>
Try it Yourself »

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;
?>
Try it Yourself »

❮ PHP Keywords
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.