[thelist] PHP: static vars

Raymond Camden jedimaster at macromedia.com
Thu Oct 18 07:25:57 CDT 2001


Coming from a CF perspective, is it fair to say that static vars could
be used like server vars? Ie, I can use it as a pseudo-caching type
technique? Something like so...

(pseudo-code)
<?
function displayTop10() {
   static $result = "";
   if($result == "") {
     //do a process, like a query, that may be a bit slow
     $result = ....;
   }
   echo $result;
}
?>

Of course, I understand that unlike CF server vars, $result would only
exist in the function, but that's ok. My main question is will it
persist.

Also, how long do PHP static vars persist? 

=======================================================================
Raymond Camden, Principal Spectra Compliance Engineer for Macromedia

Email    : jedimaster at macromedia.com
Yahoo IM : morpheus

"My ally is the Force, and a powerful ally it is." - Yoda 






More information about the thelist mailing list