Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-35001

convert_to_array anti-cycle algorithm messes with valid data

XMLWordPrintable

    • MOODLE_22_STABLE, MOODLE_23_STABLE
    • MOODLE_22_STABLE, MOODLE_23_STABLE
    • wip-MDL-35001-master
    • Hide

      Can not be tested directly but we can test that context is passed to filepicker correctly:

      1. As admin/teacher inside any course open filepicker (from any resource filemanager or tinyMCE textarea)
      2. Make sure that when you go to 'Server files' you are by default in the root folder of the current course
      3. If this course has legacy files, you can see them in filepicker
      Show
      Can not be tested directly but we can test that context is passed to filepicker correctly: As admin/teacher inside any course open filepicker (from any resource filemanager or tinyMCE textarea) Make sure that when you go to 'Server files' you are by default in the root folder of the current course If this course has legacy files, you can see them in filepicker

      The function convert_to_array() loses valid data.

      For example, it doesn't accept:

      array('first' => array('second'), 'third' => array('second'));

      By passing this array to convert_to_array, it will only return: array('first' => array('second'));

      This is caused by the anti-cycle checking. While similar code may work in other languages, in PHP, arrays with the same value can't be differentiated, so you can't check if an array is the same instance and another.

      function convert_to_array($var) {
          $result = array();
          $references = array();
          // loop over elements/properties
          foreach ($var as $key => $value) {
              // recursively convert objects
              if (is_object($value) || is_array($value)) {
                  // but prevent cycles
                  if (!in_array($value, $references)) {          // PROBLEM HERE
                      $result[$key] = convert_to_array($value);
                      $references[] = $value;
                  }
              } else {
                  // simple values are untouched
                  $result[$key] = $value;
              }
          }
          return $result;
      }

            marina Marina Glancy
            brodock Gabriel Mazetto (Inactive)
            Dan Poltawski Dan Poltawski
            Jason Fowler Jason Fowler
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.