`static` keyword inside function?

It makes the function remember the value of the given variable ($has_run in your example) between multiple calls.

You could use this for different purposes, for example:

function doStuff() {
  static $cache = null;

  if ($cache === null) {
     $cache="%heavy database stuff or something%";
  }

  // code using $cache
}

In this example, the if would only be executed once. Even if multiple calls to doStuff would occur.

Leave a Comment

tech