>This morning, a colleague of mine contacted me regarding an error that she received when she browsed to one of her courses. The error came up as ‘Coding error detected, it must be fixed by a programmer: PHP catchable fatal error’. Googling around, there were many people getting the same error with different debug details so I thought I would take a look at the debug. Fortunately, we haven’t had many errors so but it the debug came up as:

Debug info: Argument 2 passed to has_capability() must be an instance of context, null given, called in blocks\glossary_random\block_glossary_random.php on line 134 and defined
Error code: codingerror

Stack trace:

  • line 397 of      \lib\setuplib.php: coding_exception thrown
  • line 355 of      \lib\accesslib.php: call t-o default_error_handler()
  • line 134 of      \blocks\glossary_random\block_glossary_random.php: call to      has_capability()
  • line 281 of \blocks\moodleblock.class.php:      call to block_glossary_random->get_content()
  • line 232 of      \blocks\moodleblock.class.php: call to block_base->formatted_contents()
  • line 929 of      \lib\blocklib.php: call to block_base->get_content_for_output()
  • line 981 of      \lib\blocklib.php: call to block_manager->create_block_contents()
  • line 352 of      \lib\blocklib.php: call to block_manager->ensure_content_created()
  • line 99 of      \theme\afterburner\layout\default.php: call to      block_manager->region_has_content()
  • line 765 of      \lib\outputrenderers.php: call to include()
  • line 712 of      \lib\outputrenderers.php: call to core_renderer->render_page_layout()
  • line 225 of      \course\view.php: call to core_renderer->header()

From what I could determine, it appears that this is a hangover from our recent Moodle upgrade. The way to solve it is to remove the block itself and allow Moodle to reinstall straight away afterwards. Then, re-add the block to the course and all is well. Very strange.