MDL-67307 core: Fix onject creation from empty value cases
authorEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 19 Nov 2019 17:54:46 +0000 (18:54 +0100)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Fri, 22 Nov 2019 00:40:42 +0000 (01:40 +0100)
The "creating default object from empty value" warning is now consistently
thrown if a falsy value is promoted into an stdClass object. Previously some
cases like `$null->prop[0] = $val` missed this warning.

lib/outputcomponents.php
mod/assign/locallib.php

index c339f5d..505e04d 100644 (file)
@@ -3251,6 +3251,9 @@ class initials_bar implements renderable, templatable {
             if ($letter == $this->current) {
                 $groupletter->selected = $this->current;
             }
+            if (!isset($data->group[$groupnumber])) {
+                $data->group[$groupnumber] = new stdClass();
+            }
             $data->group[$groupnumber]->letter[] = $groupletter;
         }
 
index ebf3236..f1b8c80 100644 (file)
@@ -2457,6 +2457,8 @@ class assign {
      * @return array An array of userids
      */
     protected function get_grading_userid_list($cached = false, $useridlistid = '') {
+        global $SESSION;
+
         if ($cached) {
             if (empty($useridlistid)) {
                 $useridlistid = $this->get_useridlist_key_id();