Php entry constant _ PHP Tutorial

Source: Internet
Author: User
Php entry constant. Constants are used to temporarily store a value like variables, but constants are different from variables in many ways. Constants: 1. data cannot be changed during program execution. the scope of constants is full constants, like variables, used to temporarily store a value, but constants are different from variables in many ways.

Constant:
1. data cannot be changed during program execution, and the scope of constants is global.
2. the constant name is similar to the variable name, but it does not contain the dollar symbol "$ ". A valid constant name starts with a letter or underline followed by any number of letters, numbers, or underscores.
3. constants in PHP are generally both system constants and custom constants.

========================================================== ========================================================== =

We will probably say that this will be introduced later.

1. the default constant _ FILE _ refers to the FILE name and path of the PHP program;
2. the default constant _ LINE _ refers to the number of lines in the PHP program;
3. _ CLASS name;

: Use the define () function to define a constant,

Syntax format: bool define (string $ name, mixed $ value [, bool $ case_insensitive = false])

Name: specifies the constant name (in uppercase ).
Value: specifies the value of a constant. (Only scalar and null are allowed. The scalar type is integer, floating point, string or Boolean. You can also define the type of constant value as resource, but this is not recommended and may cause unknown conditions .)
Insensitive: specifies whether the constant name is case sensitive. If it is set to true, it is case insensitive. if it is set to false, it is case sensitive. If this parameter is not set, the default value false is case sensitive.

========================================================== ========================================================== =

Let's take an example:

 

After learning about this example, we can write constants in uppercase.

At the same time, we also need to pay attention to constant printing:

1. when you want to print constants, you cannot enclose them in quotation marks, just like in the above example;

2. print constants using join operators

 

Here we can see whether constants are simple in the past, but there are also many usage methods, for example, the most commonly used one is:

Define a constant to determine illegal calls between pages. Specifically, when we create a webpage homepage, we often separate the homepage from the first and second files, at this time, we need to prevent unauthorized operations and directly call these two files. at this time, we will directly add such code in these two files.

 

Add the following code to the homepage (the homepage should introduce the header and foot files. the specific introduction method will be mentioned later. if you are interested, you can introduce your own Baidu Google php file)

 

The above is just a small example. I will talk about it later or explore it myself.

Bytes. Constants: 1. data cannot be changed during program execution, and the scope of constants is full...

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.