2

I am a newbie to Moodle. I am trying to create a local plug which would do tasks (sending email) automatically when user is enrolled / unenrolled.

While developing this plugin, I am trying to echo or print_r some information for debug and tracing purposes.

The code is as simple as

function perform_enrol($eventdata){
        echo 'Hello World';
        print_r($eventdata);
        return true;
}

However, when the code executes, I get the following error occurs:

> Syntax Error File:
> http://192.168.10.60/moodle/theme/yui_combo.php?3.9.1/build/simpleyui/simpleyui.js&3.9.1/build/loader/loader.js
> Line: 18541

When I comment out the echo and print_r , the code works fine. The same problem continues for print_object , debug or any other printing functions.

Is there a specific way to print from plugins. I have used these functions in core code in past and seems to work fine.

Nis
  • 1,469
  • 15
  • 24

2 Answers2

4

When I'm debugging Moodle, I usually use error_log to print the message right to the error log of the web server (/var/log/apache2/error.log in a Debian-like distribution with Apache).

So, to inspect some variable, I need to use a function that return it as a string. Something like this:

error_log('My variable x is: ' . print_r($variable, true));

Or:

error_log('My variable x is: ' . var_export($variable, true));

Take a look at this question for more information: How can I capture the result of var_dump to a string?

Community
  • 1
  • 1
franzlorenzon
  • 5,845
  • 6
  • 36
  • 58
0

This is not the issue with the debug message from the plugin. This is due to outputting a message before an Ajax request. Please check if there are any ajax request in the particular plugin or in Moodle default pages. There is no specific debug messages specific for plugins. You can use any php built in debug functions.

Hope this helps.

gnuwings
  • 950
  • 7
  • 8