Minimal drupal_static example

Public

Minimal drupal_static example

</> CopyGet raw version
php
  1. function mymodule_do_calculations() {
  2. // get a reference to a static variable named after the function
  3. $destination = &drupal_static(__FUNCTION__);
  4.  
  5. // if we have already a value in the static cache ...
  6. if (isset($destination)) {
  7. // return it
  8. return $destination;
  9. }
  10. else {
  11. // assigning a value also sets the static cache (as drupal_static returns the variable by reference)
  12. $destination = 'bla';
  13. return $destination;
  14. }
  15. }