欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php类中常量的用法举例

程序员文章站 2022-05-29 21:08:55
...
  1. class Employee {
  2. //定义常量
  3. const AVAILABLE = 0;
  4. const OUT_OF_STOCK = 1;
  5. public $status;
  6. }
  7. print Employee::AVAILABLE;
  8. ?>
复制代码

例2,定义类中的常量

  1. class math_functions {

  2. //定义常量
  3. const PI = '3.14159265';
  4. const E = '2.7182818284';
  5. const EULER = '0.5772156649';
  6. /* 在这里定义其它的常量与方法... */
  7. }
  8. echo math_functions::PI;

  9. ?>
复制代码