Why some php frameworks define constants such as FOPEN_READFOPEN_READ_WRITE

Source: Internet
Author: User
In the file function. Isn't it simple to write w and w + directly? why do we need to go around? Some frameworks even define the 60 minute-minute 60 seconds as constants, and there is a long constant name. Why do constants need to be used for such things that will never change? In addition, I think it is written as $ t360. .. and then called in the file function. Isn't it simple to write w and w + directly? why do we need to go around?
Some frameworks even define the 60 minute-minute 60 seconds as constants, and there is a long constant name. Why do constants need to be used for such things that will never change? In addition, I think the format $ t = 3600*24 is not quite readable.

Reply content:

In the file function. Isn't it simple to write w and w + directly? why do we need to go around?
Some frameworks even define the 60 minute-minute 60 seconds as constants, and there is a long constant name. Why do constants need to be used for such things that will never change? In addition, I think the format $ t = 3600*24 is not quite readable.

Thank you!

  • The full name of a variable is used to increase readability. for example, single-letter functions have been criticized for The Times before thinkphp5, but they are not readable and can't be understood as soon as they are seen.

  • Constants are generally defined in one file or in the same location for easy maintenance.

  • It can be called repeatedly in multiple places. Once modified, you only need to change one place.

This value must have been called many times by the entire project. if it is not set as a constant, it is likely to be missed if you want to modify this value.

1 The current time is defined as a constant to reduce the time error, which is generally defined at the entry. Because the business logic exists, the request time is not the same as the data warehouse receiving time. For example, when a user clicks to submit an answer, your business logic is to execute 0.1 billion cycles and then write them into the database. The operation time recorded by your database is different from the actual user's operation time.

2. prevent time difference caused by multiple use of time ()

3. there is a lot of pressure on storage, and there is a cloud. there is a first framework written like this. before the new framework is developed, it will certainly be referenced by others.

Like a judgment statement

if($a>1){$a=1;}

Some people write it like this.

if($a>1) $a=1;

Some people write it like this.

$a>1 and  $a=1;

There is something like this:

$a>1 && $a=1;

As long as you can understand it, you can use one of your habits.

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.