PHP constant crash

Source: Internet
Author: User
Tags scalar

1 Simple Assignment

1  <?php  // Preliminary simple to assign a constant value of 2  define('PI ', 3.14); 3  Echo PI

2 Parametric analysis

Define (name, Value,bool)

First parameter

   Name constant names are generally named in uppercase.

A second parameter

value To assign a value to a parameter, it must be a scalar (integer, float, Boolean, String type).

First parameter

  If the bool constant name is case-insensitive , the default is False when the value is not assigned.  

<?  define(' NUM ', 3.14,trueecho NUM;  // The result of the output is 3.14 Define (' num ', 3.14,falseecho NUM;  // The result of the output is num Define (' NUM ', 3.14echo NUM;  // The result of the output is num//where the  second third is the same situation.

3 Some characteristics of constants

    • A constant can only be assigned a value once.
    • by definded (), you can detect whether a variable has been assigned a value.
<? PHP      Define (' NUM ', 3.14);     Var_dump (defined// output is bool (true)

4 The difference between a variable and a constant

    1. Variables can be assigned directly and constants can only be define () to assign values
    2. The name of a constant cannot be used in $, while a variable can.
    3. Constants are not scoped anywhere defined as global constants, and variables have scopes.
    4. Once a constant is defined, the variable can be modified.
    5. The value of a constant can only be scalar.

5 new features for PHP 5.3

<? PHP Define (' NUM ', 3.14); Echo   NUM; Define ('-_-# ', 3.14); // echo  -_-#;  Obviously cannot output echoconstant//php5.3 constant can handle this special case

Purely their own learning experience, but also hope that we have a lot of support and suggestions.

PHP constant crash

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.