The const in PHP

Source: Internet
Author: User

Basic syntax:

Const constant NAME = value;

How to access:

Class Name:: Constant Name or interface name:: Constant Name

Attention:

1 The constant name should be all uppercase, and the preceding cannot have the $ symbol, the constant must have an initial value when defined.

2 If you do not want a member variable to be modified and you want the value of the variable to be fixed, then you can modify the member variable with const so that the variable becomes constant automatically.

3 The const can not be preceded by the public and other modifiers, the const default is public

Cases:

<?php
Class a{
Const tax_rate=0.08;
Public Function Paytax ($val) {
return $val *a::tax_rate; []
return $val *self::tax_rate;
}
}
$a =new A ();
echo $a->paytax (100);
?>

Url:http://www.bianceng.cn/webkf/php/201701/50498.htm

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.