php – Moodle error: SyntaxError Unexpected token m in JSON at position 0

I’ve encountered this error in Moodle (v3.11), and was wondering if anyone knows of a fix.

I have a block plugin that I am building with my team. All four of us are getting the same error.

After installing, when I click on the “Add a Block” button in the Moodle Dashboard, it is throwing this error:

Unexpected token m in JSON at position 0

SyntaxError: Unexpected token m in JSON at position 0
at parse (<anonymous>)
at http://localhost/moodle/lib/javascript.php/1643153825/lib/jquery/jquery-3.5.1.min.js:2:79369
at l (http://localhost/moodle/lib/javascript.php/1643153825/lib/jquery/jquery-3.5.1.min.js:2:79486)
at XMLHttpRequest.<anonymous> (http://localhost/moodle/lib/javascript.php/1643153825/lib/jquery/jquery-3.5.1.min.js:2:82254)

I have narrowed down the code that is causing the error to a simple echo call:

Note: I’ve been using echo to temporarily display information from the functions I’m developing in the block.

example (throwing the unexpected “m” at position 0).

echo 'mod id: ' . $moduleid . "<br>"; 

While exploring the error, the m in “Unexpected token m in JSON at position 0” always shows the first character in the first echo block in my code, regardless of which or how many echo calls I have in the block.

As this is my first coding job, and I’ve only been using Moodle and PHP for only about 3 weeks now, I am concerned that I may have done something wrong with my echo call? The error throws when using both ‘single’ and “double” quotes.

Why would adding an echo to a block plugin cause a syntax error when clicking “Add a Block” in Moodle 3.11?

Read more here: Source link