ecometer

Use static variables

(Development)
#48

When the situazion allows it, use static variables to avoid running the same code several times. You will thus prevent unnecessary CPU usage.
This is especially effective for resource-intensive procedures.

To only load a heavy-to-load parser once, use static variables:

private function dataParserLoad() { 
    static $done = FALSE;
    if (!$done) {
      require_once APPLICATION_PATH_APP . '/ libraries/DataParser/Parser.php';
      $this->parser = new DataParser();
      $done = TRUE;
    }
}