Problem with calculated questions on 2.8.3+ (Build: 20150219)

Problem with calculated questions on 2.8.3+ (Build: 20150219)

by Daniel Neis Araujo -
Number of replies: 2
Picture of Core developers Picture of Plugin developers Picture of Translators

Hello,


some users on the institution I work on are facing problems with Calculated Questions on version  2.8.3+ (Build: 20150219)

It seems that it is related to MDL-46148 but i cannot access this tracker issue to confirm (the only references i've found is https://moodle.org/mod/forum/discuss.php?d=264266 and http://git.moodle.org/gw?p=moodle.git&a=search&h=HEAD&st=commit&s=MDL-46148)

I've tracked down the problem to calculate_raw function on question/type/calculated/question.php

Here is the code:



435     protected function calculate_raw($expression) {
436         // This validation trick from http://php.net/manual/en/function.eval.php .
437         if (!@eval('return true; $result = ' . $expression . ';')) {
438             throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', $expression);
439         }
440         return eval('return ' . $expression . ';');
441     } 

I've removed the "@" to show the errors so I could get the parameters passed to the functions (not only the stack trace that moodle shows) . Here is a copy of what xdebug shows:

( ! ) Parse error: syntax error, unexpected '{' in /home/daniel/public_html/2moodle/question/type/calculated/question.php(437) : eval()'d code on line 1
Call Stack
#TimeMemoryFunctionLocation
10.0008305808{main}( )../review.php:0
20.170125752928quiz_attempt::create( $attemptid = 7 )../review.php:45
30.170125753424quiz_attempt::create_helper( $conditions = array ('id' => 7) )../attemptlib.php:517
40.173026050632quiz_attempt->__construct( $attempt = class stdClass { public $id = '7'; public $quiz = '1'; public $userid = '9'; public $attempt = '1'; public $uniqueid = '7'; public $layout = '1,0,2,0,3,0,4,0,5,0,6,0'; public $currentpage = '5'; public $preview = '0'; public $state = 'finished'; public $timestart = '1416585118'; public $timefinish = '1416588082'; public $timemodified = '1416588082'; public $timecheckstate = '0'; public $sumgrades = '5.66667' }, $quiz = class stdClass { public $id = '1'; public $course = '2'; public $name = 'Lista 7C'; public $intro = ''; public $introformat = '1'; public $timeopen = '0'; public $timeclose = '1417139700'; public $timelimit = '0'; public $overduehandling = 'autosubmit'; public $graceperiod = '0'; public $preferredbehaviour = 'deferredfeedback'; public $attempts = '0'; public $attemptonlast = '0'; public $grademethod = '4'; public $decimalpoints = '2'; public $questiondecimalpoints = '-1'; public $reviewattempt = '69904'; public $reviewcorrectness = '16'; public $reviewmarks = '16'; public $reviewspecificfeedback = '16'; public $reviewgeneralfeedback = '16'; public $reviewrightanswer = '16'; public $reviewoverallfeedback = '0'; public $questionsperpage = '1'; public $navmethod = 'free'; public $shufflequestions = '0'; public $shuffleanswers = '1'; public $sumgrades = '6.00000'; public $grade = '10.00000'; public $timecreated = '0'; public $timemodified = '1416583975'; public $password = ''; public $subnet = ''; public $browsersecurity = '-'; public $delay1 = '0'; public $delay2 = '0'; public $showuserpicture = '0'; public $showblocks = '0'; public $completionattemptsexhausted = '0'; public $completionpass = '0'; public $cmid = '3' }, $cm = class stdClass { public $id = '3'; public $course = '2'; public $module = '16'; public $instance = '1'; public $section = '1'; public $idnumber = ''; public $added = '1416569962'; public $score = '0'; public $indent = '0'; public $visible = '1'; public $visibleold = '1'; public $groupmode = '0'; public $groupingid = '0'; public $completion = '0'; public $completiongradeitemnumber = NULL; public $completionview = '0'; public $completionexpected = '0'; public $showdescription = '0'; public $availability = NULL; public $name = 'Lista 7C'; public $modname = 'quiz' }, $course = class stdClass { public $id = '2'; public $category = '1'; public $sortorder = '10001'; public $fullname = 'nananana'; public $shortname = 'aca'; public $idnumber = ''; public $summary = ''; public $summaryformat = '1'; public $format = 'weeks'; public $showgrades = '1'; public $newsitems = '5'; public $startdate = '1421200800'; public $marker = '0'; public $maxbytes = '0'; public $legacyfiles = '0'; public $showreports = '0'; public $visible = '1'; public $visibleold = '1'; public $groupmode = '0'; public $groupmodeforce = '0'; public $defaultgroupingid = '0'; public $lang = ''; public $calendartype = ''; public $theme = ''; public $timecreated = '1421178817'; public $timemodified = '1421178817'; public $requested = '0'; public $enablecompletion = '0'; public $completionnotify = '0'; public $cacherev = '1425928270' }, $loadquestions = ??? )../attemptlib.php:507
50.173226053504question_engine::load_questions_usage_by_activity( $qubaid = '7', $db = ??? )../attemptlib.php:487
60.173226053888question_engine_data_mapper->load_questions_usage_by_activity( $qubaid = '7' )../lib.php:84
70.173426060160question_usage_by_activity::load_from_records( $records = class mysqli_native_moodle_recordset { protected $result = class mysqli_result { public $current_field = NULL; public $field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL }; protected $current = array ('qubaid' => '7', 'contextid' => '44', 'component' => 'mod_quiz', 'preferredbehaviour' => 'deferredfeedback', 'questionattemptid' => '37', 'questionusageid' => '7', 'slot' => '1', 'behaviour' => 'deferredfeedback', 'questionid' => '15', 'variant' => '7', 'maxmark' => '1.0000000', 'minfraction' => '0.0000000', 'maxfraction' => '1.0000000', 'flagged' => '0', 'questionsummary' => 'Analise o programa abaixo e indique qual será a saída apresentada. A saída é um valor numérico inteiro. \n\n/* ------ inicio ------ */ \n\n#include <stdio.h> \n\n \n\nint func1(int x){ \n\n return x + x; \n\n} \n\n \n\nint main(){ \n\n int a = 2, t = 3; \n\n a = func1(a); \n\n a = func1(a + t); \n\n printf("%d\\n",a); \n\n} \n\n/* ------ fim ------ */ \n\n ', 'rightanswer' => '14,00', 'responsesummary' => '14', 'timemodified' => '1416588082', 'attemptstepid' => '94', 'sequencenumber' => '1', 'state' => 'complete', 'fraction' => NULL, 'timecreated' => '1416585182', 'userid' => '9', 'name' => 'answer', 'value' => '14') }, $qubaid = '7' )../datalib.php:418
80.173426065056question_attempt::load_from_records( $records = class mysqli_native_moodle_recordset { protected $result = class mysqli_result { public $current_field = NULL; public $field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL }; protected $current = array ('qubaid' => '7', 'contextid' => '44', 'component' => 'mod_quiz', 'preferredbehaviour' => 'deferredfeedback', 'questionattemptid' => '37', 'questionusageid' => '7', 'slot' => '1', 'behaviour' => 'deferredfeedback', 'questionid' => '15', 'variant' => '7', 'maxmark' => '1.0000000', 'minfraction' => '0.0000000', 'maxfraction' => '1.0000000', 'flagged' => '0', 'questionsummary' => 'Analise o programa abaixo e indique qual será a saída apresentada. A saída é um valor numérico inteiro. \n\n/* ------ inicio ------ */ \n\n#include <stdio.h> \n\n \n\nint func1(int x){ \n\n return x + x; \n\n} \n\n \n\nint main(){ \n\n int a = 2, t = 3; \n\n a = func1(a); \n\n a = func1(a + t); \n\n printf("%d\\n",a); \n\n} \n\n/* ------ fim ------ */ \n\n ', 'rightanswer' => '14,00', 'responsesummary' => '14', 'timemodified' => '1416588082', 'attemptstepid' => '94', 'sequencenumber' => '1', 'state' => 'complete', 'fraction' => NULL, 'timecreated' => '1416585182', 'userid' => '9', 'name' => 'answer', 'value' => '14') }, $questionattemptid = '37', $observer = class question_engine_unit_of_work { protected $quba = class question_usage_by_activity { protected $id = '7'; protected $preferredbehaviour = 'deferredfeedback'; protected $context = class context_module { protected $_id = 44; protected $_contextlevel = 70; protected $_instanceid = '3'; protected $_path = '/1/3/18/44'; protected $_depth = '4' }; protected $owningcomponent = 'mod_quiz'; protected $questionattempts = array (); protected $observer = ... }; protected $modified = FALSE; protected $attemptsmodified = array (); protected $attemptsadded = array (); protected $stepsadded = array (); protected $stepsmodified = array (); protected $stepsdeleted = array () }, $preferredbehaviour = 'deferredfeedback' )../questionusage.php:862
90.178727051944qtype_calculated_question->apply_attempt_state( $step = class question_attempt_step_read_only { private ${question_attempt_step}:id = '93'; private ${question_attempt_step}:state = class question_state_todo { }; private ${question_attempt_step}:fraction = NULL; private ${question_attempt_step}:timecreated = '1416585118'; private ${question_attempt_step}:userid = '9'; private ${question_attempt_step}:data = array ('_separators' => ',$.', '_var_a' => '2', '_var_t' => '3'); private ${question_attempt_step}:files = array () } )../questionattempt.php:1415
100.178727052040qtype_calculated_question_helper::apply_attempt_state( $question = class qtype_calculated_question { public $datasetloader = class qtype_calculated_dataset_loader { protected $questionid = '15'; protected $itemsavailable = NULL }; public $vs = class qtype_calculated_variable_substituter { protected $values = array ('a' => '2', 't' => '3'); protected $decimalpoint = '.'; protected $search = array (0 => '{a}', 1 => '{t}'); protected $safevalue = array (0 => '(2)', 1 => '(3)'); protected $prettyvalue = array (0 => '2', 1 => '3'); public $replace = array () }; public $synchronised = '0'; public $answers = array (23 => class qtype_numerical_answer { public $tolerance = 0; public $tolerancetype = '1'; public $id = '23'; public $answer = '{a00} + {a01} + {a10} + {a11}'; public $answerformat = '2'; public $fraction = '1.0000000'; public $feedback = ''; public $feedbackformat = '1'; public $correctanswerlength = '0'; public $correctanswerformat = '1' }); public $unitdisplay = '3'; public $unitgradingtype = '0'; public $unitpenalty = '0.1000000'; public $ap = class qtype_numerical_answer_processor { protected $units = array (); protected $decsep = '.'; protected $thousandssep = ','; protected $unitsbefore = FALSE; protected $regex = NULL }; public $shownumcorrect = FALSE; public $id = '15'; public $category = '4'; public $contextid = '18'; public $parent = '0'; public $qtype = class qtype_calculated { public $wizardpagesnumber = 3; protected $fileoptions = array ('subdirs' => TRUE, 'maxfiles' => -1, 'maxbytes' => 0) }; public $name = 'Calcular resultado I'; public $questiontext = '<p>Analise o programa abaixo e indique qual será a saída apresentada. A saída é um valor numérico inteiro. </p>\n<p><span style="font-family: \'courier new\', courier, monospace;">/* ------ inicio ------ */ </span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;">#include &lt;stdio.h&gt;</span><span style="font-family: \'courier new\', courier, monospace; line-height: 1.231;"> </span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;">int main(){</span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"> int a[2][2], soma;</span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"> a[0][0] = {a00};</span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span> a[0][1] = {a01};</span></span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span><span> a[1][0] = {a10};</span></span></span> </p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span> a[1][1] = {a11};</span></span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span> soma = <span>a[0][0] + <span>a[0][1] + <span>a[1][0] + <span>a[1][1];</span></span></span></span></span></span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span style="line-height: 1.231;"> printf("%d\\n",soma);</span></span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;">}</span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;">/* ------ fim ------ */</span></p>\n<p class="p1"> </p>'; public $questiontextformat = '1'; public $generalfeedback = ''; public $generalfeedbackformat = '1'; public $defaultmark = 1; public $length = '1'; public $penalty = 0.3333333; public $stamp = 'moodle.ufsc.br+141121122949+3ebsIM'; public $version = 'moodle.ufsc.br+141126163415+ltpDMm'; public $hidden = '0'; public $timecreated = '1416572989'; public $timemodified = '1417019655'; public $createdby = '21'; public $modifiedby = '21'; public $hints = array () }, $step = class question_attempt_step_read_only { private ${question_attempt_step}:id = '93'; private ${question_attempt_step}:state = class question_state_todo { }; private ${question_attempt_step}:fraction = NULL; private ${question_attempt_step}:timecreated = '1416585118'; private ${question_attempt_step}:userid = '9'; private ${question_attempt_step}:data = array ('_separators' => ',$.', '_var_a' => '2', '_var_t' => '3'); private ${question_attempt_step}:files = array () } )../question.php:59
110.178827055968qtype_calculated_question->calculate_all_expressions( )../question.php:169
120.178827056144qtype_calculated_variable_substituter->calculate( $expression = '{a00} + {a01} + {a10} + {a11}', '0', '1' )../question.php:70
130.178927056504qtype_calculated_variable_substituter->calculate_raw( $expression = '{a00} + {a01} + {a10} + {a11}' )../question.php:426

( ! ) Parse error: syntax error, unexpected '{' in /home/daniel/public_html/2moodle/question/type/calculated/question.php(440) : eval()'d code on line 1
Call Stack
#TimeMemoryFunctionLocation
10.0008305808{main}( )../review.php:0
20.170125752928quiz_attempt::create( $attemptid = 7 )../review.php:45
30.170125753424quiz_attempt::create_helper( $conditions = array ('id' => 7) )../attemptlib.php:517
40.173026050632quiz_attempt->__construct( $attempt = class stdClass { public $id = '7'; public $quiz = '1'; public $userid = '9'; public $attempt = '1'; public $uniqueid = '7'; public $layout = '1,0,2,0,3,0,4,0,5,0,6,0'; public $currentpage = '5'; public $preview = '0'; public $state = 'finished'; public $timestart = '1416585118'; public $timefinish = '1416588082'; public $timemodified = '1416588082'; public $timecheckstate = '0'; public $sumgrades = '5.66667' }, $quiz = class stdClass { public $id = '1'; public $course = '2'; public $name = 'Lista 7C'; public $intro = ''; public $introformat = '1'; public $timeopen = '0'; public $timeclose = '1417139700'; public $timelimit = '0'; public $overduehandling = 'autosubmit'; public $graceperiod = '0'; public $preferredbehaviour = 'deferredfeedback'; public $attempts = '0'; public $attemptonlast = '0'; public $grademethod = '4'; public $decimalpoints = '2'; public $questiondecimalpoints = '-1'; public $reviewattempt = '69904'; public $reviewcorrectness = '16'; public $reviewmarks = '16'; public $reviewspecificfeedback = '16'; public $reviewgeneralfeedback = '16'; public $reviewrightanswer = '16'; public $reviewoverallfeedback = '0'; public $questionsperpage = '1'; public $navmethod = 'free'; public $shufflequestions = '0'; public $shuffleanswers = '1'; public $sumgrades = '6.00000'; public $grade = '10.00000'; public $timecreated = '0'; public $timemodified = '1416583975'; public $password = ''; public $subnet = ''; public $browsersecurity = '-'; public $delay1 = '0'; public $delay2 = '0'; public $showuserpicture = '0'; public $showblocks = '0'; public $completionattemptsexhausted = '0'; public $completionpass = '0'; public $cmid = '3' }, $cm = class stdClass { public $id = '3'; public $course = '2'; public $module = '16'; public $instance = '1'; public $section = '1'; public $idnumber = ''; public $added = '1416569962'; public $score = '0'; public $indent = '0'; public $visible = '1'; public $visibleold = '1'; public $groupmode = '0'; public $groupingid = '0'; public $completion = '0'; public $completiongradeitemnumber = NULL; public $completionview = '0'; public $completionexpected = '0'; public $showdescription = '0'; public $availability = NULL; public $name = 'Lista 7C'; public $modname = 'quiz' }, $course = class stdClass { public $id = '2'; public $category = '1'; public $sortorder = '10001'; public $fullname = 'nananana'; public $shortname = 'aca'; public $idnumber = ''; public $summary = ''; public $summaryformat = '1'; public $format = 'weeks'; public $showgrades = '1'; public $newsitems = '5'; public $startdate = '1421200800'; public $marker = '0'; public $maxbytes = '0'; public $legacyfiles = '0'; public $showreports = '0'; public $visible = '1'; public $visibleold = '1'; public $groupmode = '0'; public $groupmodeforce = '0'; public $defaultgroupingid = '0'; public $lang = ''; public $calendartype = ''; public $theme = ''; public $timecreated = '1421178817'; public $timemodified = '1421178817'; public $requested = '0'; public $enablecompletion = '0'; public $completionnotify = '0'; public $cacherev = '1425928270' }, $loadquestions = ??? )../attemptlib.php:507
50.173226053504question_engine::load_questions_usage_by_activity( $qubaid = '7', $db = ??? )../attemptlib.php:487
60.173226053888question_engine_data_mapper->load_questions_usage_by_activity( $qubaid = '7' )../lib.php:84
70.173426060160question_usage_by_activity::load_from_records( $records = class mysqli_native_moodle_recordset { protected $result = class mysqli_result { public $current_field = NULL; public $field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL }; protected $current = array ('qubaid' => '7', 'contextid' => '44', 'component' => 'mod_quiz', 'preferredbehaviour' => 'deferredfeedback', 'questionattemptid' => '37', 'questionusageid' => '7', 'slot' => '1', 'behaviour' => 'deferredfeedback', 'questionid' => '15', 'variant' => '7', 'maxmark' => '1.0000000', 'minfraction' => '0.0000000', 'maxfraction' => '1.0000000', 'flagged' => '0', 'questionsummary' => 'Analise o programa abaixo e indique qual será a saída apresentada. A saída é um valor numérico inteiro. \n\n/* ------ inicio ------ */ \n\n#include <stdio.h> \n\n \n\nint func1(int x){ \n\n return x + x; \n\n} \n\n \n\nint main(){ \n\n int a = 2, t = 3; \n\n a = func1(a); \n\n a = func1(a + t); \n\n printf("%d\\n",a); \n\n} \n\n/* ------ fim ------ */ \n\n ', 'rightanswer' => '14,00', 'responsesummary' => '14', 'timemodified' => '1416588082', 'attemptstepid' => '94', 'sequencenumber' => '1', 'state' => 'complete', 'fraction' => NULL, 'timecreated' => '1416585182', 'userid' => '9', 'name' => 'answer', 'value' => '14') }, $qubaid = '7' )../datalib.php:418
80.173426065056question_attempt::load_from_records( $records = class mysqli_native_moodle_recordset { protected $result = class mysqli_result { public $current_field = NULL; public $field_count = NULL; public $lengths = NULL; public $num_rows = NULL; public $type = NULL }; protected $current = array ('qubaid' => '7', 'contextid' => '44', 'component' => 'mod_quiz', 'preferredbehaviour' => 'deferredfeedback', 'questionattemptid' => '37', 'questionusageid' => '7', 'slot' => '1', 'behaviour' => 'deferredfeedback', 'questionid' => '15', 'variant' => '7', 'maxmark' => '1.0000000', 'minfraction' => '0.0000000', 'maxfraction' => '1.0000000', 'flagged' => '0', 'questionsummary' => 'Analise o programa abaixo e indique qual será a saída apresentada. A saída é um valor numérico inteiro. \n\n/* ------ inicio ------ */ \n\n#include <stdio.h> \n\n \n\nint func1(int x){ \n\n return x + x; \n\n} \n\n \n\nint main(){ \n\n int a = 2, t = 3; \n\n a = func1(a); \n\n a = func1(a + t); \n\n printf("%d\\n",a); \n\n} \n\n/* ------ fim ------ */ \n\n ', 'rightanswer' => '14,00', 'responsesummary' => '14', 'timemodified' => '1416588082', 'attemptstepid' => '94', 'sequencenumber' => '1', 'state' => 'complete', 'fraction' => NULL, 'timecreated' => '1416585182', 'userid' => '9', 'name' => 'answer', 'value' => '14') }, $questionattemptid = '37', $observer = class question_engine_unit_of_work { protected $quba = class question_usage_by_activity { protected $id = '7'; protected $preferredbehaviour = 'deferredfeedback'; protected $context = class context_module { protected $_id = 44; protected $_contextlevel = 70; protected $_instanceid = '3'; protected $_path = '/1/3/18/44'; protected $_depth = '4' }; protected $owningcomponent = 'mod_quiz'; protected $questionattempts = array (); protected $observer = ... }; protected $modified = FALSE; protected $attemptsmodified = array (); protected $attemptsadded = array (); protected $stepsadded = array (); protected $stepsmodified = array (); protected $stepsdeleted = array () }, $preferredbehaviour = 'deferredfeedback' )../questionusage.php:862
90.178727051944qtype_calculated_question->apply_attempt_state( $step = class question_attempt_step_read_only { private ${question_attempt_step}:id = '93'; private ${question_attempt_step}:state = class question_state_todo { }; private ${question_attempt_step}:fraction = NULL; private ${question_attempt_step}:timecreated = '1416585118'; private ${question_attempt_step}:userid = '9'; private ${question_attempt_step}:data = array ('_separators' => ',$.', '_var_a' => '2', '_var_t' => '3'); private ${question_attempt_step}:files = array () } )../questionattempt.php:1415
100.178727052040qtype_calculated_question_helper::apply_attempt_state( $question = class qtype_calculated_question { public $datasetloader = class qtype_calculated_dataset_loader { protected $questionid = '15'; protected $itemsavailable = NULL }; public $vs = class qtype_calculated_variable_substituter { protected $values = array ('a' => '2', 't' => '3'); protected $decimalpoint = '.'; protected $search = array (0 => '{a}', 1 => '{t}'); protected $safevalue = array (0 => '(2)', 1 => '(3)'); protected $prettyvalue = array (0 => '2', 1 => '3'); public $replace = array () }; public $synchronised = '0'; public $answers = array (23 => class qtype_numerical_answer { public $tolerance = 0; public $tolerancetype = '1'; public $id = '23'; public $answer = '{a00} + {a01} + {a10} + {a11}'; public $answerformat = '2'; public $fraction = '1.0000000'; public $feedback = ''; public $feedbackformat = '1'; public $correctanswerlength = '0'; public $correctanswerformat = '1' }); public $unitdisplay = '3'; public $unitgradingtype = '0'; public $unitpenalty = '0.1000000'; public $ap = class qtype_numerical_answer_processor { protected $units = array (); protected $decsep = '.'; protected $thousandssep = ','; protected $unitsbefore = FALSE; protected $regex = NULL }; public $shownumcorrect = FALSE; public $id = '15'; public $category = '4'; public $contextid = '18'; public $parent = '0'; public $qtype = class qtype_calculated { public $wizardpagesnumber = 3; protected $fileoptions = array ('subdirs' => TRUE, 'maxfiles' => -1, 'maxbytes' => 0) }; public $name = 'Calcular resultado I'; public $questiontext = '<p>Analise o programa abaixo e indique qual será a saída apresentada. A saída é um valor numérico inteiro. </p>\n<p><span style="font-family: \'courier new\', courier, monospace;">/* ------ inicio ------ */ </span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;">#include &lt;stdio.h&gt;</span><span style="font-family: \'courier new\', courier, monospace; line-height: 1.231;"> </span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;">int main(){</span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"> int a[2][2], soma;</span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"> a[0][0] = {a00};</span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span> a[0][1] = {a01};</span></span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span><span> a[1][0] = {a10};</span></span></span> </p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span> a[1][1] = {a11};</span></span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span> soma = <span>a[0][0] + <span>a[0][1] + <span>a[1][0] + <span>a[1][1];</span></span></span></span></span></span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;"><span style="line-height: 1.231;"> printf("%d\\n",soma);</span></span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;">}</span></p>\n<p class="p1"><span class="s1" style="font-family: \'courier new\', courier, monospace;">/* ------ fim ------ */</span></p>\n<p class="p1"> </p>'; public $questiontextformat = '1'; public $generalfeedback = ''; public $generalfeedbackformat = '1'; public $defaultmark = 1; public $length = '1'; public $penalty = 0.3333333; public $stamp = 'moodle.ufsc.br+141121122949+3ebsIM'; public $version = 'moodle.ufsc.br+141126163415+ltpDMm'; public $hidden = '0'; public $timecreated = '1416572989'; public $timemodified = '1417019655'; public $createdby = '21'; public $modifiedby = '21'; public $hints = array () }, $step = class question_attempt_step_read_only { private ${question_attempt_step}:id = '93'; private ${question_attempt_step}:state = class question_state_todo { }; private ${question_attempt_step}:fraction = NULL; private ${question_attempt_step}:timecreated = '1416585118'; private ${question_attempt_step}:userid = '9'; private ${question_attempt_step}:data = array ('_separators' => ',$.', '_var_a' => '2', '_var_t' => '3'); private ${question_attempt_step}:files = array () } )../question.php:59
110.178827055968qtype_calculated_question->calculate_all_expressions( )../question.php:169
120.178827056144qtype_calculated_variable_substituter->calculate( $expression = '{a00} + {a01} + {a10} + {a11}', '0', '1' )../question.php:70
130.178927056504qtype_calculated_variable_substituter->calculate_raw( $expression = '{a00} + {a01} + {a10} + {a11}' )../question.php:426

If I comment the exception throw, the warnings are shown and the page is rendered correctly.

Could you please help us?
Kind regards,
Daniel
Average of ratings: -
In reply to Daniel Neis Araujo

Re: Problem with calculated questions on 2.8.3+ (Build: 20150219)

by Marcus Green -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers

What is the problem that your users are experiencing?

In reply to Daniel Neis Araujo

Re: Problem with calculated questions on 2.8.3+ (Build: 20150219)

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

As far as I can see, the question defines two variables, {a} and {t}. Therefore you cannot evaluate the expression {a00} + {a01} + {a10} + {a11}. Those variables are undefined.

If you try to edit this question in Moodle, then you probably won't be able to save it. The form validation will give you errors. Where did this question come from? I am guessing it was imported somehow.

The calcuate_raw function is working exactly the way it is supposed to (though I agree that the error message could be more helpful.)