I tested upgrading one of our Moodle sites from version 3.8.1 to 3.9.6 latest release and after all the upgrading was performed experienced a strange behavior on the 3.9.6 site.
On top of the main section (section 0) of the front page, there was an error outputted:
Undefined index: numsections in {website file path}/index.php on line 115.
The same error does not occur in Moodle 3.8.1 yet the code is consistent between the two sites. I have enclosed two screenshots, one that does not have the error is Moodle 3.8.1:
and the one with the error is Moodle 3.9.6 latest release:
I put some debug output (var_dump()) to show the contents of the array being referenced and those outputs are showing on both screenshots. As you can see, the contents of the array are identical and lack a "numsections" array item.
I decided to get around this issue to modify the code in index.php and test for isset() before referencing that array member, which is proper. However, what befuddles me is why did the behavior change with 3.9.6 latest release when the code is identical?
Here is the original code:
} else if ($siteformatoptions['numsections'] > 0) {
Here is my modified code:
} else if (isset($siteformatoptions['numsections']) && ($siteformatoptions['numsections'] > 0)) {
By doing this I was able to get past this issue, however what befuddles me and which I have not yet identified is that in the 3.8.1 site that section of code is not hit. The conditions prefacing that bit of code did not also get hit when technically speaking therefore code execution should have fallen to the else if condition test and then therefore failed just like the 3.9.6 latest release did but doesn't. Code snippet:
// Print Section or custom info. if (!empty($CFG->customfrontpageinclude)) { // Pre-fill some variables that custom front page might use. $modnames = get_module_types_names(); $modnamesplural = get_module_types_names(true); $mods = $modinfo->get_cms(); include($CFG->customfrontpageinclude); } else if (isset($siteformatoptions['numsections']) && ($siteformatoptions['numsections'] > 0)) { echo $courserenderer->frontpage_section1(); }
I don't have the time presently to look into this further at the moment since today is a day for new term course preparations and I'm swamped with bad course builds and massive questions from instructors, but thought I would mention this bit in this forum in case anyone else has had a similar problem, and wants to solve the error from showing on their site, or in case someone knows what the underlying issue is and can provide some helpful feedback.