what are your favorite PHP programming trick(s)?
I myself like Resession (Session Manager)
what are your favorite PHP programming trick(s)?
I myself like Resession (Session Manager)
Static function cacheing:
function cachedFunction($foo)
{
static $result = array();
if (isset($result[$foo])) {
return $result[$foo];
}
$return[$foo] = resultOfSomeTimeConsumingStuff();
return $return[$foo];
}
If the result of the function will not change during the run of your application you can get much faster repeated calls to the cached function.
A well designed application won't need this but it's pretty useful to squeeze a lot of performance out of old or poorly engineered systems without much effort.
I've worked on project where this reduced the time for the average HTTP request to about 50%. because the app was repeatedly calling the same functions without actually needing a "fresh" result.
Just keep in mind: This trick may give you out-of-date data! So be careful.