Override a function in a contrib module My company received a maintenance contract for a website developed in Drupal 7. The Drupal 7 website uses the Quiz contrib module, ver. 7.x-4.0-rc10. The module is used to implement a feature where authenticated users answer questions to tests.

When an authenticated user completes the test and views his result, the following notice errors are displayed on the results page,


Notice: Undefined index: nid in quiz_take_quiz() (line 2078 of C:\wamp64\www\........\modules\contrib\quiz\quiz.module).
Notice: Undefined index: vid in quiz_take_quiz() (line 2078 of C:\wamp64\www\........\modules\contrib\quiz\quiz.module).
Notice: Trying to get property 'type' of non-object in quiz_take_quiz() (line 2082 of C:\wamp64\www\........\modules\contrib\quiz\quiz.module).
Notice: Undefined index: in quiz_take_quiz() (line 2082 of C:\wamp64\www\........\modules\contrib\quiz\quiz.module).
Notice: Trying to get property 'is_valid' of non-object in quiz_take_quiz() (line 2084 of C:\wamp64\www\........\modules\contrib\quiz\quiz.module).


The Quiz module has a function, quiz_take_quiz($quiz). 

As part of contract signed by my company, I have to resolve all notices. Therefore, what I intend to do is override this function and modify the exact line which is responsible for throwing the above notices (line no. 2078) and add a variable validation there.

However being a newbie to Drupal development I don't know where to start and what to do. I do know that modifying the code in a contrib module is not the best practice. I have hidden the path to the .module file with ........ to maintain privacy.

Can anyone please provide me the solution to this?
After going through all of your replies and a few internal discussions in my company, I have decided to modify the Quiz module's code by creating and applying a patch, quiz_notice_messages_in_result_screen.patch. 

As per the information provided by Alfred Armstrong's the said patch will be solely used for our company's internal purposes, so as to find a way around the Drupal's general practice of reporting a contrib module's issues and suggesting patches for the same.

Below are the contents of the quiz_notice_messages_in_result_screen.patch file.

diff --git a/modules/contrib/quiz/quiz.module b/modules/contrib/quiz/quiz.module
index dd2b88c..e551aac 100644
--- a/modules/contrib/quiz/quiz.module
+++ b/modules/contrib/quiz/quiz.module
@@ -2075,13 +2075,19 @@ function quiz_take_quiz($quiz) {
     $_SESSION['quiz_' . $quiz-&gt;nid]['quiz_questions'][0]['rid'] = $_SESSION['quiz_' . $quiz-&gt;nid]['result_id'];
     $_SESSION['quiz_' . $quiz-&gt;nid]['previous_quiz_questions'][] = $_SESSION['quiz_' . $quiz-&gt;nid]['quiz_questions'][0];
     $former_question_array = array_shift($_SESSION['quiz_' . $quiz-&gt;nid]['quiz_questions']);
+    if (empty($former_question_array['nid']) || empty($former_question_array['vid'])) {
+      $former_question_array['nid'] = $quiz-&gt;nid;
+      $former_question_array['vid'] = $quiz-&gt;vid;
+    }
     $former_question = node_load($former_question_array['nid'], $former_question_array['vid']);

     // Call hook_evaluate_question().
     $types = _quiz_get_question_types();
-    $module = $types[$former_question-&gt;type]['module'];
+    $module = empty($types[$former_question-&gt;type]['module']) ? '' : $types[$former_question-&gt;type]['module'];
     $result = module_invoke($module, 'evaluate_question', $former_question, $_SESSION['quiz_' . $quiz-&gt;nid]['result_id']);
-    $q_passed_validation = $result-&gt;is_valid;
+    if(isset($result-&gt;is_valid)) {
+      $q_passed_validation = $result-&gt;is_valid;
+    }
     $check_jump = TRUE;
     if ($q_passed_validation === TRUE) {
       quiz_store_question_result($quiz, $result, array('set_msg' =&gt; TRUE, 'question_data' =&gt; $former_question_array));


Thank you No Sssweat, Alfred Armstrong and Alan Dixon for your inputs.