If the value of $return has a number in the first character position then the switch statement may give an unexpected response. This is because switch statements evaluate each case with the "==" operator by default.

Two possible alternatives would be:
use the "===" test for each case

switch ($return) {
  case $return === MENU_NOT_FOUND:
    drupal_not_found();
    break;
  case $return === MENU_ACCESS_DENIED:
    drupal_access_denied();
    break;
  case $return === MENU_SITE_OFFLINE:
    drupal_site_offline();
    break;
  default:
    // Print any value (including an empty string) except NULL or undefined:
    if (isset($return)) {
      print theme('page', $return);
    }
    break;
}

test for a numeric before the switch

if (is_numeric($return)){
  switch ($return) {
    case $return == MENU_NOT_FOUND:
      drupal_not_found();
      break;
    case $return == MENU_ACCESS_DENIED:
      drupal_access_denied();
      break;
    case $return == MENU_SITE_OFFLINE:
      drupal_site_offline();
      break;
  }
}
else {    
    // Print any value (including an empty string) except NULL or undefined:
    if (isset($return)) {
      print theme('page', $return);
    }  
}

there is some discussion here that may shed some light on a "best" solution.

Comments

ChrisKennedy’s picture

Status: Active » Closed (duplicate)
jsloan’s picture

I see that after all the discusion my suggestion "test for a numeric before the switch" was used. Thanks for the update.