What is the best practice way to do Class in-function caching in PHP
. Right now I am doing:
Class Functions {
public static function foo() {
static $local_result;
if(!empty($local_result) {
return $local_result;
}
$result = some_slow_http_request();
$local_result = $result;
return $result;
}
}
So:
// First request makes an http request
Functions::foo();
// Second time, pull from memory, does not make an http request
Functions::foo();
Is there a better way? Are namespace collisions possible if code somewhere else changes $local_result
, thinking it is a separate var?