Why some PHP frameworks define constants such as Fopen_read Fopen_read_write

Source: Internet
Author: User
, and then called in the file function. Directly write w,w+ is not quite concise, why do you want to go around the circle?
Some frameworks even define the 60 of a minute with 60 seconds as a constant, and a long constant name. Why do you use constants for something that will never change? And I think it's not a poor form of readability to write $t=3600*24.

Reply content:

, and then called in the file function. Directly write w,w+ is not quite concise, why do you want to go around the circle?
Some frameworks even define the 60 of a minute with 60 seconds as a constant, and a long constant name. Why do you use constants for something that will never change? And I think it's not a poor form of readability to write $t=3600*24.

Xie invited

    • Variable full name is for readability, example thinkphp5 the previous time single-letter function has been criticized is no readability can not see on the understanding

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

    • Can be repeatedly called by multiple places, once modified only one place

Because this value is definitely called by the entire project many times, if not configured as a constant, once you want to modify this value, it is very likely to miss out.

1 The current time is defined as constant to reduce the time error, which is generally defined at the entrance. Because of the business logic, the request time is not equal to your data storage time. For example, when a user clicks submit an answer, your business logic is to execute 100 million cycles and then write to the database. Then the operating time of your database record and the actual user's operating time are in a bad value.

2 prevent time () Multiple use causes time difference

3 There is a large extent is installed force, conform to, there is the first framework to write, the new framework will certainly refer to others before the development, but also the same writing.

Like a judgment statement.

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

Some people write this

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

Some people write this

$a>1 and  $a=1;

And there's this writing

$a>1 && $a=1;

As long as you can read it, you can use one of your own 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.