Constants for PHP Object Const definition Classes

Source: Internet
Author: User


Const

* The const-decorated class has a constant member property
* 1. Constants are recommended to use uppercase and cannot use $
* 2. Constants must be given a good initial value at the time of declaration
* 3. Constants are accessed in the same way as static, but are read-only
* Access class name outside class:: Constant Name
* Inside the class Access self:: constant name

<?phpheader (' Content-type:text/html;charset=utf-8 ');/* * define (' Constant name ', ' value ')  *  Class cannot be used define the member property of the definition  * const  adornment class is a constant  * 1. Constants are recommended to use uppercase, and $ * 2 cannot be used. Constants must be given a good initial value at the time of declaration  * 3. Constants are accessed in the same way as static, but can only be read  *  accessed outside the class         class name:: Constant Name  *  accessing        self within the class:: Constant name  *  * final    Classes and methods  * static  properties and Methods  */define (' ROOT ',  str_replace (' \ \ ',  '/',  dirname (_ _file__)));// \  is an escape character   so to represent a backslash   character, two backslashes are required, which means that the backslash is escaped with an escape character echo root;     class Person{        const NAME =  "Jin Sha Harbor";        static function say () {         echo  "I Am" .self::name;        }     }    perSon::say (); 



This article is from the "Jin Sha Harbor" blog, please be sure to keep this source http://11410485.blog.51cto.com/11400485/1844677

Constants for PHP Object Const definition Classes

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.