The reason is that you're using menu_addblank() with slot set to 0. This causes it to not increase the number of total slots, so 7 is beyond the range of the menu. If you have 5 items and 2 blanks (with slot=0), then your total range is 5.
Also, your range starts at 0. So if you have 5 items, keys 0-4 are valid but 5 is not. It is similar to arrays.