XF 2.0 Should I use time() or \XF::$time in my code?

I noticed that Xenforo uses \XF::$time in many places in the code.
If I want to get current time, should I use time() or \XF::$time?
What is difference of the two?

Thanks,
Tommi
 
We tend to use time() as much as possible these days. That’s specifically the current server time stamp when the function runs. By contrast $time is the time stamp at the start of the request and it stays the same for the duration of the request.

Generally it’s just a case of weighing up which is most relevant to your usage but 9 times out of 10 you can likely just use either.
 
Two calls to time() during the execution of your script may return a different result (because you know - time passes) - so if it's important to have something consistent to compare to, use \XF::$time because it won't change.

I tend to find myself using \XF::$time in most cases, but usually just as a matter of personal preference. It's rare that it matters - although I did have a case the other day where it was better use time() instead.
 
Top Bottom