Exception - syntax error, unexpected '|', expecting ';', or '{'

Exception - syntax error, unexpected '|', expecting ';', or '{'

by James Becker -
Number of replies: 7
When upgrading to 4.0.1+ I'm getting this error message AFTER the "Server Checks:

Exception - syntax error, unexpected '|', expecting ';', or '{'

the only options is "Continue" which takes me back to the Server Checks" page in a loop. Ideas??
Average of ratings: -
In reply to James Becker

Re: Exception - syntax error, unexpected '|', expecting ';', or '{'

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

Enable debugging to show more details with the error. If the error is preventing you getting to the settings you can instead add the following lines to config.php:

@error_reporting(E_ALL | E_STRICT);
@ini_set('display_errors', '1');
$CFG->debug = (E_ALL | E_STRICT);
$CFG->debugdisplay = 1;

These lines must appear before the require_once(__DIR__ . '/lib/setup.php'); line.

This kind of error is frequently due to a mismatch between the version of Moodle or a plugin, and the PHP version.

In reply to Leon Stringer

Re: Exception - syntax error, unexpected '|', expecting ';', or '{'

by James Becker -
Thank you for the response.
I have added the code as you suggested. This is what I get. Ideas?

Exception - syntax error, unexpected '|', expecting ';' or '{'
More information about this error
Debug info:
Error code: generalexceptionmessage×Dismiss this notification
Stack trace:
line 96 of /admin/tool/mfa/classes/plugininfo/factor.php: ParseError thrown
line ? of unknownfile: call to core_component::classloader()
line ? of unknownfile: call to spl_autoload_call()
line 450 of /lib/classes/plugin_manager.php: call to class_exists()
line 261 of /lib/classes/plugin_manager.php: call to core_plugin_manager::resolve_plugininfo_class()
line 282 of /lib/classes/plugin_manager.php: call to core_plugin_manager->load_enabled_plugins()
line 197 of /availability/classes/tree.php: call to core_plugin_manager->get_enabled_plugins()
line 144 of /availability/classes/info.php: call to core_availability\tree->__construct()
line 114 of /availability/classes/info.php: call to core_availability\info->decode_availability()
line 196 of /availability/classes/info.php: call to core_availability\info->get_availability_tree()
line 3175 of /lib/modinfolib.php: call to core_availability\info->is_available()
line 3236 of /lib/modinfolib.php: call to section_info->get_available()
line 3137 of /lib/modinfolib.php: call to section_info->get_uservisible()
line 75 of /course/format/classes/output/local/content/section/summary.php: call to section_info->__get()
line 145 of /course/format/classes/output/local/content/section.php: call to core_courseformat\output\local\content\section\summary->export_for_template()
line 94 of /course/format/classes/output/local/content/frontpagesection.php: call to core_courseformat\output\local\content\section->export_for_template()
line 497 of /lib/outputrenderers.php: call to core_courseformat\output\local\content\frontpagesection->export_for_template()
line 108 of /course/format/classes/output/section_renderer.php: call to plugin_renderer_base->render()
line 2208 of /course/renderer.php: call to core_courseformat\output\section_renderer->render()
line 137 of /index.php: call to core_course_renderer->frontpage_section1()

Do you see anything here I can fix to resolve this issue? Thank you for your time.
In reply to James Becker

Re: Exception - syntax error, unexpected '|', expecting ';', or '{'

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

As Ken's suggested, it looks like the Multi-factor authentication (tool_mfa) plugin is causing the problem. Make sure you have the latest version which supports your Moodle version.

If you're still having trouble please tell us your version of this plugin shown on the Plugins Overview page (click Additional plugins to see only these).
In reply to James Becker

Re: Exception - syntax error, unexpected '|', expecting ';', or '{'

by Ken Task -
Picture of Particularly helpful Moodlers
The environment check checks only for PHP version + extensions and DB version compatibility with code you have.   It doesn't check plugins/addons.

Appears you have in /admin/tool/ an addon called 'mfa' - multifactor authentication?


You might need to upgrade those files first before trying to upgrade core.

OR ... you could try to hide it from moodle ... in /admin/tool/ rename the directory 'mfa' to '.mfa' ... see the 'dot' in front of 'mfa'?   That hides the directory from moodle/webserver.  And might let you finish core upgrade, but you still have broken mfa.

My guess.
'SoS', Ken

In reply to Ken Task

Re: Exception - syntax error, unexpected '|', expecting ';', or '{'

by James Becker -
I've renamed the mfa folder to .mfa as you suggested. I no longer get the original error but now I get a "Plugin dependencies check" error as shown in the attached image. Ideas??
Attachment moodleFails.png
In reply to James Becker

Re: Exception - syntax error, unexpected '|', expecting ';', or '{'

by Leon Stringer -
Picture of Core developers Picture of Particularly helpful Moodlers

The original syntax error makes some sense now: you've got some Moodle 4.3 files mixed in with you Moodle 4.0 source code.

The copy of tool_mfa wasn't the one from the Plugins directory but the one that got added to core in Moodle 4.3 and requires PHP 8.0 or later. And these new Plugin dependencies check errors are because your copy of the Database activity (mod_data) is from Moodle 4.3, which is what the Requires: Moodle 2023100400 refers to.

So you need to make sure your Moodle source code (and the plugins and themes) are all the expected version. You could do this by following the steps to upgrade to the latest minor version, i.e. if you're running Moode 4.0.x then upgrade to Moodle 4.0.12. Basically:

  1. Move your current Moodle source code into a backup folder.
  2. Download the latest Moodle 4.0.x release.
  3. Extract the files into your site's source code folder.
  4. Copy config.php from the backup folder into the source code folder.
  5. Download and extract any plugins and themes you have installed.
  6. Log in as an admin to perform the update.
Average of ratings: Useful (2)
In reply to Leon Stringer

Re: Exception - syntax error, unexpected '|', expecting ';', or '{'

by James Becker -
Thanks for the reply. All is well now, and I have 4.0.12 up and running with no errors! 😎
Many thanks to Leon and Ken!