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

Cast both value and units to int for configduration write_setting

XMLWordPrintable

    • MOODLE_311_STABLE, MOODLE_400_STABLE
    • MOODLE_311_STABLE, MOODLE_400_STABLE
    • MDL-74886-master
    • Hide

      Testing pre-requisite: Site is running on PHP8

      1. Go to a Administration > Courses > Course default settings
      2. set the value for the Course duration setting to either a blank box, or a string like "abc" (not a number)
      3. Click save changes
      4. Verify you do not end up with an exception displayed to the user
      Show
      Testing pre-requisite: Site is running on PHP8 Go to a Administration > Courses > Course default settings set the value for the Course duration setting to either a blank box, or a string like "abc" ( not a number) Click save changes Verify you do not end up with an exception displayed to the user

      The duration config type takes two values, a value and a unit.

      The unit is generally always something that can be cast to int.

      However, the value, which is provided by the user - might not be. If no value is entered, or a value which does not cast to an int - then php performs a string*string operation instead of int*int.

      For php before php8 - this simply resulted in a Warning - and the default validation was able to confirm it wasn't set correctly and prompt the user for a better value.

      From php8 however, string*string opts now raise a TypeError exception - so the user instead sees "Exception - Unsupported operand types: string * string".

       

      The fix for this is rather trivial - rather casting the result of u * v to an int, cast each value separately to an int before multiplying them.

        1. MDL-74886 error.png
          MDL-74886 error.png
          40 kB
        2. MDL-74886_v400.mp4
          3.22 MB
        3. MDL-74886_v311.mp4
          3.03 MB
        4. MDL-74886_master.mp4
          2.81 MB

            aolley Adam Olley
            aolley Adam Olley
            Simey Lameze Simey Lameze
            Jun Pataleta Jun Pataleta
            John Edward Pedregosa John Edward Pedregosa
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours, 6 minutes
                3h 6m

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