and then call it in the file function. Isn’t it quite simple to just write w, w+ directly? Why go around in circles?
Some frameworks even define the 60 (there are 60 seconds in a minute) as a constant, and there is a long constant name. Why do we need to use constants for something that will never change? And I think writing it in the form of $t=3600*24 is not bad at readability
and then call it in the file function. Isn’t it quite simple to just write w, w+ directly? Why go around in circles?
Some frameworks even define the 60 (there are 60 seconds in a minute) as a constant, and there is a long constant name. Why do we need to use constants for something that will never change? And I think writing it in the form of $t=3600*24 is not bad at readability
Thanks for the invitation
The full name of the variable is to increase readability. For example, in the era before thinkphp5, single-letter functions were always criticized because they were not readable and could not be understood at first sight
Constants are generally defined in a file or the same location for easy maintenance
can be called repeatedly in multiple places. Once there is any modification, you only need to change one place
Because this value must be called many times by the entire project, if it is not configured as a constant, once this value is modified, it is likely to be missed.
1 The current time is defined as a constant to reduce time errors, and is usually defined at the entrance. Because there is business logic, the request time is not equal to the time your data is stored in the database. For example, when the user clicks to submit an answer, your business logic at this time is to execute a loop 100 million times and then write it to the database. Then there is a difference between the operation time recorded in your database and the real user's operation time.
2 Prevent time() from being used multiple times causing time differences
3 To a large extent, it is just pretentious and echoing what others say. The first framework is written like this. Before developing a new framework, I will definitely refer to other people's and write it in the same way.
It’s like a judgment statement
<code>if($a>1){ $a=1; }</code>
Some people write like this
<code>if($a>1) $a=1;</code>
Some people write like this
<code>$a>1 and $a=1;</code>
Some people write like this
<code>$a>1 && $a=1;</code>
As long as you can understand it, just use the one you are used to.