Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Small improvement for Smarty class constructor

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development
View previous topic :: View next topic  
Author Message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Dec 06, 2012 2:14 pm    Post subject: Small improvement for Smarty class constructor Reply with quote

Code:
      $this->start_time = version_compare(phpversion(), '5.4.0', '<')
        ? microtime(true)
        : $_SERVER['REQUEST_TIME_FLOAT'];
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Dec 06, 2012 2:26 pm    Post subject: Reply with quote

Actually, I'm using more convoluted variant of this code in my overloaded constructor.
Code:
    if(defined('toolPageGenerationStarted'))
    {
      $this->start_time = toolPageGenerationStarted;
    }
    else
    {
      $this->start_time = version_compare(phpversion(), '5.4.0', '<')
        ? microtime(true)
        : $_SERVER['REQUEST_TIME_FLOAT'];
    }


toolPageGenerationStarted constant is defined very early in script execution (in fact, it is part of my debugging framework, and included before any other scripts, if available).
Not that it matters for 5.4, but for earlier versions you get more reliable results.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Dec 06, 2012 2:29 pm    Post subject: Reply with quote

Thats fine if you want the start time to be the float time of the server. You could also just test isset($_SERVER['REQUEST_TIME_FLOAT']) instead of trusting the PHP version for it.
Back to top
View user's profile Send private message Visit poster's website
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Dec 13, 2012 4:52 pm    Post subject: Reply with quote

mohrt wrote:
Thats fine if you want the start time to be the float time of the server. You could also just test isset($_SERVER['REQUEST_TIME_FLOAT']) instead of trusting the PHP version for it.

Do read the code, please. I'm not "trusting" PHP version. I'm checking for it.
$_SERVER['REQUEST_TIME_FLOAT'] was implemented in PHP 5.4.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Smarty Development All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP