function my_big_function() { static $result; // Function has already run if ( $result !== null ) return $result; // Lot of work here to determine $result $result = 'whatever'; return $result; } Also see: http://stackoverflow.com/questions/6188994/static-keyword-inside-function