Home  >  Article  >  Backend Development  >  Examples of usage of constants in php classes

Examples of usage of constants in php classes

WBOY
WBOYOriginal
2016-07-25 08:56:11889browse
  1. class Employee {
  2. //Define constants
  3. const AVAILABLE = 0;
  4. const OUT_OF_STOCK = 1;
  5. public $status;
  6. }
  7. print Employee::AVAILABLE;
  8. ?>
Copy code

Example 2, define constants in classes

  1. class math_functions {

  2. //Define constant
  3. const PI = '3.14159265';
  4. const E = '2.7182818284';
  5. const EULER = '0.57721 56649';
  6. / * Define other constants and methods here... */
  7. }

  8. echo math_functions::PI;

  9. ?>

Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn