original_string: public static function instance($courseorid, $userid = 0) {
          global $USER;
          if (is_object($courseorid)) {
              $course = $courseorid;
          } else {
              $course = (object)array('id' => $courseorid);
          }
          if (empty($userid)) {
              $userid = $USER->id;
          }
  
          if (!empty(self::$instancecache[$course->id])) {
              if (self::$instancecache[$course->id]->userid == $userid &&
                      (!isset($course->cacherev) ||
                      $course->cacherev == self::$instancecache[$course->id]->get_course()->cacherev)) {
                  // This course's modinfo for the same user was recently retrieved, return cached.
                  self::$cacheaccessed[$course->id] = microtime(true);
                  return self::$instancecache[$course->id];
              } else {
                  // Prevent potential reference problems when switching users.
                  self::clear_instance_cache($course->id);
              }
          }
          $modinfo = new course_modinfo($course, $userid);
  
          // We have a limit of MAX_MODINFO_CACHE_SIZE entries to store in static variable.
          if (count(self::$instancecache) >= MAX_MODINFO_CACHE_SIZE) {
              // Find the course that was the least recently accessed.
              asort(self::$cacheaccessed, SORT_NUMERIC);
              $courseidtoremove = key(array_reverse(self::$cacheaccessed, true));
              self::clear_instance_cache($courseidtoremove);
          }
  
          // Add modinfo to the static cache.
          self::$instancecache[$course->id] = $modinfo;
          self::$cacheaccessed[$course->id] = microtime(true);
  
          return $modinfo;
      }
code: public static function instance($courseorid, $userid = 0) {
          global $USER;
          if (is_object($courseorid)) {
              $course = $courseorid;
          } else {
              $course = (object)array('id' => $courseorid);
          }
          if (empty($userid)) {
              $userid = $USER->id;
          }
  
          if (!empty(self::$instancecache[$course->id])) {
              if (self::$instancecache[$course->id]->userid == $userid &&
                      (!isset($course->cacherev) ||
                      $course->cacherev == self::$instancecache[$course->id]->get_course()->cacherev)) {
                  // This course's modinfo for the same user was recently retrieved, return cached.
                  self::$cacheaccessed[$course->id] = microtime(true);
                  return self::$instancecache[$course->id];
              } else {
                  // Prevent potential reference problems when switching users.
                  self::clear_instance_cache($course->id);
              }
          }
          $modinfo = new course_modinfo($course, $userid);
  
          // We have a limit of MAX_MODINFO_CACHE_SIZE entries to store in static variable.
          if (count(self::$instancecache) >= MAX_MODINFO_CACHE_SIZE) {
              // Find the course that was the least recently accessed.
              asort(self::$cacheaccessed, SORT_NUMERIC);
              $courseidtoremove = key(array_reverse(self::$cacheaccessed, true));
              self::clear_instance_cache($courseidtoremove);
          }
  
          // Add modinfo to the static cache.
          self::$instancecache[$course->id] = $modinfo;
          self::$cacheaccessed[$course->id] = microtime(true);
  
          return $modinfo;
      }
code_tokens: public static function instance ( $ courseorid , $ userid = 0 ) { global $ USER ; if ( is_object ( $ courseorid ) ) { $ course = $ courseorid ; } else { $ course = ( object ) array ( 'id' => $ courseorid ) ; } if ( empty ( $ userid ) ) { $ userid = $ USER -> id ; } if ( ! empty ( self :: $ instancecache [ $ course -> id ] ) ) { if ( self :: $ instancecache [ $ course -> id ] -> userid == $ userid && ( ! isset ( $ course -> cacherev ) || $ course -> cacherev == self :: $ instancecache [ $ course -> id ] -> get_course ( ) -> cacherev ) ) { // This course's modinfo for the same user was recently retrieved, return cached. self :: $ cacheaccessed [ $ course -> id ] = microtime ( true ) ; return self :: $ instancecache [ $ course -> id ] ; } else { // Prevent potential reference problems when switching users. self :: clear_instance_cache ( $ course -> id ) ; } } $ modinfo = new course_modinfo ( $ course , $ userid ) ; // We have a limit of MAX_MODINFO_CACHE_SIZE entries to store in static variable. if ( count ( self :: $ instancecache ) >= MAX_MODINFO_CACHE_SIZE ) { // Find the course that was the least recently accessed. asort ( self :: $ cacheaccessed , SORT_NUMERIC ) ; $ courseidtoremove = key ( array_reverse ( self :: $ cacheaccessed , true ) ) ; self :: clear_instance_cache ( $ courseidtoremove ) ; } // Add modinfo to the static cache. self :: $ instancecache [ $ course -> id ] = $ modinfo ; self :: $ cacheaccessed [ $ course -> id ] = microtime ( true ) ; return $ modinfo ; }
docstring: Returns the instance of course_modinfo for the specified course and specified user
  
  This function uses static cache for the retrieved instances. The cache
  size is limited by MAX_MODINFO_CACHE_SIZE. If instance is not found in
  the static cache or it was created for another user or the cacherev validation
  failed - a new instance is constructed and returned.
  
  Used in {@link get_fast_modinfo()}
  
  @param int|stdClass $courseorid object from DB table 'course' (must have field 'id'
  and recommended to have field 'cacherev') or just a course id
  @param int $userid User id to populate 'availble' and 'uservisible' attributes of modules and sections.
  Set to 0 for current user (default). Set to -1 to avoid calculation of dynamic user-depended data.
  @return course_modinfo
docstring_tokens: Returns the instance of course_modinfo for the specified course and specified user