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

Array count() error in MOODLE v4.0 after update to PHP v8.0

XMLWordPrintable

    • MOODLE_311_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE
    • MOODLE_400_STABLE, MOODLE_401_STABLE
    • MDL-76376_m41
    • Hide
      1. Use PHP 8.0
      2. Modify /mod/scorm/datamodels/scormlib.php to add this code immediately before line 571

        $scoes->elements = null;
        

      3. Load the ZZMoodleTransformTesting_minimal-1.zip  scorm package and make sure that the following error is not displayed:

        Exception - count(): Argument #1 ($value) must be of type Countable|array, null given
         
        Debug info:
        Error code: generalexceptionmessage Stack trace:
        line (~571) of /mod/scorm/datamodels/scormlib.php: TypeError thrown 

        Note: There are other visible errors/warnings, but they are not in the scope of this issue.

      Show
      Use PHP 8.0 Modify /mod/scorm/datamodels/scormlib.php to add this code immediately before line 571 $scoes ->elements = null; Load the ZZMoodleTransformTesting_minimal-1.zip   scorm package and make sure that the following error is not displayed: Exception - count(): Argument # 1 ($value) must be of type Countable|array, null given   Debug info: Error code: generalexceptionmessage Stack trace: line (~ 571 ) of /mod/scorm/datamodels/scormlib.php: TypeError thrown Note : There are other visible errors/warnings, but they are not in the scope of this issue.

      We are on MOODLE version 3.11. After loading PHP 8.0 we started getting the error below when trying to open any of our SCORM packages.
      Exception - count(): Argument #1 ($value) must be of type Countable|array, null given
      Turning on debugging revealed the additional detail below:

      Debug info:
      Error code: generalexceptionmessage Stack trace:

      line 571 of /mod/scorm/datamodels/scormlib.php: TypeError thrown

      I had to change the /mnt/data/moodle/htdocs/mod/scorm/datamodels/scormlib.php file. I found a forum where someone else was mentioning this error in PHP8 and the fix was to modify the line:

      if (count($scoes->elements) > 0) {

      to:

      if (!empty($scoes->elements)) {

      Apparently since elements wasn't an array, it couldn't do a 'count' of it. But just checking to see if it's empty provides the same functionality while keeping elements as undeclared

        1. 400.png
          400.png
          149 kB
        2. bandicam 2023-03-28 12-29-01-444.mp4
          5.24 MB
        3. MDL-76376_minimal.zip
          1.02 MB
        4. MDL-76376_minimal-1.zip
          1.02 MB
        5. MDL-76376.png
          MDL-76376.png
          224 kB
        6. stable.png
          stable.png
          109 kB
        7. ZZMoodleTransformTesting_minimal.zip
          1.03 MB
        8. ZZMoodleTransformTesting_minimal-1.zip
          1.03 MB

            jrchamp Jonathan Champ
            hollimar-ia hollimar-ia
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Mihail Geshoski Mihail Geshoski
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            3 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 47 minutes
                1h 47m

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