If you compare this code you are seeing with the original (https://github.com/moodle/moodle/blob/MOODLE_35_STABLE/mod/quiz/processattempt.php) then clearly someone has been making local customisations to your code, and clearly they have made a mistake while doing so. (Perhaps they have not considered the case where $nextmod does not exist???)
Quiz
Quiz error
Denne diskusjonen har blitt stengt, og du kan derfor ikke svare i den lengre.