Examples of usage of constants in php classes

WBOY
Release: 2016-07-25 08:56:11
Original
876 people have browsed it
  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


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!