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

Recursive $cm property access causes 'Cannot access private property cm_info::*' (PHP 7.4)

    XMLWordPrintable

    Details

    • Testing Instructions:
      Hide

      There may be a way to reproduce this with the default UI rather than using a database query, but this approach definitely works...

      1. In a new course, create a Page activity with the name 'My page'.
      2. Find the cmid of the page activity by clicking on it - you should get to a url like mod/page/view.php?id=1234, where 1234 is the cmid.
      3. In your database, run this SQL which sets up invalid availability settings for the page activity:
        • UPDATE mdl_course_modules SET availability='not valid' WHERE id=1234;
        • Replace mdl_ with your database prefix, and 1234 with the cmid from above.
      4. Go to the course page.
      5. Edit settings for the course (from the gear icon).
      6. Change the full name slightly, and click 'Save and display' (this will clear the course cache),
        • EXPECTED: You should see a debugging message (possibly more than one copy of it); they should all read 'Error processing availability data for 'My page': Invalid availability text'
        • NOTE: The first error may be hidden underneath the header - you may need to view page source to see the text.

      Before this fix, one of two things happened - on PHP 7.3, you saw the same debugging message but with the cmid (1234) instead of the 'My page' text (which was as designed, but not ideal) and on PHP 7.4, the page probably died with 'Error: Cannot access private property cm_info::$name'.

      Show
      There may be a way to reproduce this with the default UI rather than using a database query, but this approach definitely works... In a new course, create a Page activity with the name 'My page'. Find the cmid of the page activity by clicking on it - you should get to a url like mod/page/view.php?id=1234, where 1234 is the cmid. In your database, run this SQL which sets up invalid availability settings for the page activity: UPDATE mdl_course_modules SET availability='not valid' WHERE id=1234; Replace mdl_ with your database prefix, and 1234 with the cmid from above. Go to the course page. Edit settings for the course (from the gear icon). Change the full name slightly, and click 'Save and display' (this will clear the course cache), EXPECTED: You should see a debugging message (possibly more than one copy of it); they should all read 'Error processing availability data for 'My page': Invalid availability text' NOTE: The first error may be hidden underneath the header - you may need to view page source to see the text. Before this fix, one of two things happened - on PHP 7.3, you saw the same debugging message but with the cmid (1234) instead of the 'My page' text (which was as designed, but not ideal) and on PHP 7.4, the page probably died with 'Error: Cannot access private property cm_info::$name'.
    • Affected Branches:
      MOODLE_310_STABLE, MOODLE_39_STABLE
    • Fixed Branches:
      MOODLE_310_STABLE, MOODLE_39_STABLE
    • Pull 3.9 Branch:
      MDL-70537-m39
    • Pull 3.10 Branch:
      MDL-70537-m310
    • Pull 3.11 Branch:
      MDL-70537-m311
    • Pull Master Branch:
      MDL-70537-master

      Description

      We experienced this error in opening a course or using Global Search.

      The error could be traced by a wrong access restriction setting on an activity (in this case BigBlueButton)

      The setting causes that even an administrator can no longer access a course nor its settings. It had to be fixed within the database.

      Complete error:
      Exception - Cannot access private property cm_info::$name
      Debug info:
      Error code: generalexceptionmessage
      Stack trace: * line 746 of /availability/classes/info.php: Error thrown

      • line ? of unknownfile: call to core_availability\info::core_availability
        {closure}

        ()

      • line 739 of /availability/classes/info.php: call to preg_replace_callback()
      • line 295 of /availability/classes/info.php: call to core_availability\info::format_info()
      • line 199 of /availability/classes/info.php: call to core_availability\info->warn_about_invalid_availability()
      • line 1892 of /lib/modinfolib.php: call to core_availability\info->is_available()
      • line 1366 of /lib/modinfolib.php: call to cm_info->obtain_dynamic_data()
      • line 1234 of /lib/modinfolib.php: call to cm_info->get_name()
      • line 269 of /theme/fordson/classes/output/core_renderer.php: call to cm_info->__get()
      • line 477 of /theme/fordson/classes/output/core_renderer.php: call to theme_fordson\output\core_renderer->generate_sections_and_activities()
      • line 219 of /lib/mustache/src/Mustache/Context.php: call to theme_fordson\output\core_renderer->fordson_custom_menu()
      • line 138 of /lib/mustache/src/Mustache/Context.php: call to Mustache_Context->findVariableInStack()
      • line 78 of /home/learn/moodledata/localcache/mustache/1608491292/fordson/__Mustache_ef507f05771d69ef1f8b9f1292e9fe09.php: call to Mustache_Context->findDot()
      • line 36 of /home/learn/moodledata/localcache/mustache/1608491292/fordson/__Mustache_251400b93ebfad86b2270cae23515d63.php: call to __Mustache_ef507f05771d69ef1f8b9f1292e9fe09->renderInternal()
      • line 67 of /lib/mustache/src/Mustache/Template.php: call to __Mustache_251400b93ebfad86b2270cae23515d63->renderInternal()
      • line 195 of /lib/outputrenderers.php: call to Mustache_Template->render()
      • line 91 of /theme/fordson/layout/course.php: call to renderer_base->render_from_template()
      • line 1374 of /lib/outputrenderers.php: call to include()
      • line 1304 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
      • line 244 of /course/view.php: call to core_renderer->header()

      Discussion topic here: https://moodle.org/mod/forum/discuss.php?d=411255#p1658650

        Attachments

        1. course_error.png
          269 kB
          Sujith Haridasan
        2. course_page.png
          180 kB
          Sujith Haridasan
        3. MDL-70537_Test Passed.PNG
          88 kB
          Gladys Basiana
        4. Schermafbeelding 2020-12-29 122227.png
          22 kB
          Richard van Iwaarden

          Activity

            People

            Assignee:
            quen Sam Marshall
            Reporter:
            elodelta Richard van Iwaarden
            Peer reviewer:
            Sujith Haridasan Sujith Haridasan
            Integrator:
            Víctor Déniz Falcón Víctor Déniz Falcón
            Tester:
            Gladys Basiana Gladys Basiana
            Participants:
            Component watchers:
            Sam Marshall, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona), Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
            Votes:
            5 Vote for this issue
            Watchers:
            17 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              10/May/21

                Time Tracking

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