Moodle
  1. Moodle
  2. MDL-39870

Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: 2.5.1
    • Component/s: Course
    • Labels:
      None
    • Testing Instructions:
      Hide
      1. Hack any module lib.php and make sure that modulename_supports() return something non-standard, like array or string or big integer
      2. Make sure you are able to add this module to the course (it appears in the "add activity or resource" window)
      3. After the module is added go to course view page, switch to editing mode and make sure that no warnings are displayed
      Show
      Hack any module lib.php and make sure that modulename_supports() return something non-standard, like array or string or big integer Make sure you are able to add this module to the course (it appears in the "add activity or resource" window) After the module is added go to course view page, switch to editing mode and make sure that no warnings are displayed
    • Affected Branches:
      MOODLE_25_STABLE
    • Fixed Branches:
      MOODLE_25_STABLE
    • Pull Master Branch:
      wip-MDL-39870-master
    • Rank:
      50615

      Description

      I have just come across this Warning/error while trying to find a fix for another bug in Clean theme. I found the same warning in Afterburner after quickly changing to that theme.

      The warning appeared as I turned Editing on in a course page. The warning message was in ever topic header. Going to Home page the message was there too, but this time above the page-header (Afterburner).

      This is the warning message and stack trace.

      Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer in C:\wamp\www\moodle26\course\renderer.php on line 372
      Call Stack
      #	Time	Memory	Function	Location
      1	0.0027	836208	{main}( )	..\index.php:0
      2	0.7515	39625544	core_renderer->header( )	..\index.php:99
      3	0.7757	40302568	core_renderer->render_page_layout( )	..\outputrenderers.php:777
      4	0.7761	40417680	include( 'C:\wamp\www\moodle26\theme\afterburner\layout\default.php' )	..\outputrenderers.php:847
      5	0.8700	50367728	block_manager->region_has_content( )	..\default.php:6
      6	0.8701	50367728	block_manager->ensure_content_created( )	..\blocklib.php:353
      7	0.8701	50367936	block_manager->create_block_contents( )	..\blocklib.php:1003
      8	4.3932	88274144	block_base->get_content_for_output( )	..\blocklib.php:951
      9	4.3933	88276336	block_list->formatted_contents( )	..\moodleblock.class.php:238
      10	4.3933	88276336	block_site_main_menu->get_content( )	..\moodleblock.class.php:764
      11	4.5842	88335080	core_course_renderer->course_section_add_cm_control( )	..\block_site_main_menu.php:131
      12	4.6722	97153288	array_key_exists ( )	..\renderer.php:372
      

        Issue Links

          Activity

          Hide
          Marina Glancy added a comment -

          I was able to reproduce it looking at the code and hacking one of the modules:

          It seems that one of the module types that Mary uses has incorrect function xxx_support($feature)

          For example, if I have a survey module in my course I hack function survey_support() in /mod/survey/lib.php to have a line like:

                  case FEATURE_MOD_ARCHETYPE:           return array();
          

          So actually this looks like a bug in one of the 3rd party modules used. But I suppose we still can add validation is_int() for module archetype in /course/renderer.php

          Show
          Marina Glancy added a comment - I was able to reproduce it looking at the code and hacking one of the modules: It seems that one of the module types that Mary uses has incorrect function xxx_support($feature) For example, if I have a survey module in my course I hack function survey_support() in /mod/survey/lib.php to have a line like: case FEATURE_MOD_ARCHETYPE: return array(); So actually this looks like a bug in one of the 3rd party modules used. But I suppose we still can add validation is_int() for module archetype in /course/renderer.php
          Hide
          Marina Glancy added a comment -

          after closer look it does look like my regression from MDL-37085

          I was moving code from function print_section_add_menu()
          https://github.com/moodle/moodle/blob/MOODLE_24_STABLE/course/lib.php#L1750
          to core_course_renderer::course_section_add_cm_control()
          https://github.com/moodle/moodle/blob/master/course/renderer.php#L352

          and did not think that modules can deifne whatever they want in xxx_support() function. We only need to filter out SYSTEM archetype completely and treat everything that is not RESOURCE as activity.

          Show
          Marina Glancy added a comment - after closer look it does look like my regression from MDL-37085 I was moving code from function print_section_add_menu() https://github.com/moodle/moodle/blob/MOODLE_24_STABLE/course/lib.php#L1750 to core_course_renderer::course_section_add_cm_control() https://github.com/moodle/moodle/blob/master/course/renderer.php#L352 and did not think that modules can deifne whatever they want in xxx_support() function. We only need to filter out SYSTEM archetype completely and treat everything that is not RESOURCE as activity.
          Hide
          Mary Evans added a comment -

          Glad you found a fix for this Marina. I'll also check to see what mod could be causing this in my Moodle site.

          Show
          Mary Evans added a comment - Glad you found a fix for this Marina. I'll also check to see what mod could be causing this in my Moodle site.
          Hide
          Dan Poltawski added a comment -

          Intgrated to master and 25, thanks Marina

          Show
          Dan Poltawski added a comment - Intgrated to master and 25, thanks Marina
          Hide
          Petr Škoda added a comment -

          works fine, thanks

          Show
          Petr Škoda added a comment - works fine, thanks
          Hide
          Dan Poltawski added a comment -
          Feature: Thanks to our superb contributors
            In order to make Moodle better
            As an integrator
            I need to thank all our contributors
          
            Scenario: Dan thanks you all
              Given I log in as "dan"
              And I see "lots of fixed issues"
              When I follow "Close integrated issues"
              Then I should see "Lots of thanks to all our contributors"
          

          Your changes are upstream

          Show
          Dan Poltawski added a comment - Feature: Thanks to our superb contributors In order to make Moodle better As an integrator I need to thank all our contributors Scenario: Dan thanks you all Given I log in as "dan" And I see "lots of fixed issues" When I follow "Close integrated issues" Then I should see "Lots of thanks to all our contributors" Your changes are upstream

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: