Php user-defined constants and class constants

Source: Internet
Author: User
Php customizes global constants and class constants *** 1. define (name, value, case_insensitive) customizes global constants. the default value is case sensitive. * 2. const defines class constants. * 3. do not use "$" * 4 before the constant name. generally, uppercase letters are used for the constant name. * Defines the global constant LANGUAGEdefine (LANGUAGE, China); ec php customizes global constants and class constants.

/*** 1. define (name, value, case_insensitive) customizes global constants. the default value is case sensitive. * 2. const defines class constants. * 3. do not use "$" * 4 before the constant name. generally, uppercase letters are used for the constant name. * /// Defines the global constant LANGUAGEdefine ('language ', 'China'); echo LANGUAGE; // languageecho language; // China // defines the global constant CNdefine ('cn ', 'China', TRUE); echo CN; // China echo cn; // China // definition class constant class ConstTest {const VERSION = '1. 0'; function ConstTest () {// class internal use "self: constant name" call, cannot use $ thisecho 'self: VERSION = '. self: VERSION ;}/// instantiate ConstTest to call the ConstTest () constructor. // call a class constant by using the class name :: the constant name is called directly without instantiation. Echo 'version = '. (ConstTest: VERSION); echo'
'; // Array get_defined_constants ([bool $ categorize = false]) returns all defined constants // print_r (get_defined_constants (true); // bool defined (string $ name) check whether the constant of the name has been defined. Echo defined ('cn ')? 'True': 'false ';

?

Print result:

Language
China
China
China
Self: VERSION = 1.0
VERSION = 1.0
True

?

Http://huangqiqing123.iteye.com/blog/1921428

?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.