/**
  * Sanitize the given key/value pair, passing any error to $errs if given.
  *
  * @param string $key The key to reference the current value in the defaults array.
  * @param mixed $value The value to be sanitized.
  * @param string[] $errs The array of errors, which will be appended with any errors found.
  *
  * @return mixed The sanitized value, falling back to the current default value when invalid value given.
  */
 public static function sanitizeParameter($key, $value, &$errs = null)
 {
     // all sanitize methods must be in the following form: sanitize<UpperCamelCaseKey>
     $funct = $key;
     $funct[0] = strtoupper($funct[0]);
     $funct = 'sanitize' . preg_replace_callback('/_([a-z])/', array(__CLASS__, 'secondCharToUpper'), $funct);
     $callable = array(__CLASS__, $funct);
     // avoid looking for method beforehand unless we're running in debug mode -- expensive call
     if (DG_Logger::logEnabled() && !method_exists(__CLASS__, $funct)) {
         DG_Logger::writeLog(DG_LogLevel::Error, __('Attempted to call invalid function: ', 'document-gallery') . implode('::', $callable), true);
     }
     // call param-specific sanitization
     $ret = call_user_func_array($callable, array($value, &$err));
     // check for error and return default
     if (isset($err)) {
         $defaults = DG_Gallery::getOptions();
         $ret = $defaults[$key];
         if (!is_null($errs)) {
             $errs[$key] = $err;
         }
     }
     return $ret;
 }