PHP Custom Big picture constants and class constants

Source: Internet
Author: User
PHP Custom Global constants and class constants
/** * 1, define (name,value,case_insensitive) custom global constants, default case Sensitive * 2, Const defines class constants. * 3, the constant name do not use "$" * 4, the name of the constant all use uppercase letters. *///defines global constants Languagedefine (' LANGUAGE ', ' China '); Echo language;//languageecho language;//China//define Global constants Cndefine (' CN ', ' China ', TRUE) echo cn;//China echo cn;//China//define class constant classes Consttest{const VERSION = ' 1.0 '; function consttest () {//class internally using "Self:: constant name" Call, Cannot use $thisecho ' self::version= '. self::version;}} Instantiate Consttest, the purpose is to call the constructor new Consttest ();//External call class constant, through the "class name:: Constant name" directly called, do not need to instantiate. 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) checks if the constant for the name is defined. Echo defined (' CN ')? ' True ': ' false ';

?

Printing results:

Language
China
China
China
self::version=1.0
version=1.0
True

?

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

?

  • Related Article

    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.