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;
    }
}
This best practice should only be applied if it is coherent with your project's specifications.
Under CC-By-NX-SA license