How to print or save internal detail of an object?

How to print or save internal detail of an object?

by wz z -
Number of replies: 8

I want to know the detail of the $eventdata variable in the function send_message($eventdata) in this file https://github.com/moodle/moodle/blob/master/message/output/email/message_output_email.php

I use "error_log('variable eventdata is: ' . print_object($eventdata));", but it only shows:

PHP message: variable eventdata is: stdClass Object 

No internal detail info sad

Average of ratings: -
In reply to wz z

Re: How to print or save internal detail of an object?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Just do

print_object($eventdata);


In reply to Tim Hunt

Re: How to print or save internal detail of an object?

by wz z -

By using print_object($eventdata); will the variable be displayed on webpage? But the function is executed in cron task, so I cannot see the detail.

In reply to wz z

Re: How to print or save internal detail of an object?

by Conn Warwicker -
Picture of Core developers Picture of Plugin developers

error_log("data: " . print_r($eventdata, true));

Average of ratings: Useful (1)
In reply to wz z

Re: How to print or save internal detail of an object?

by Andrew Lyons -
Picture of Core developers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Then store the output of the cron and view that rather than sending it to /dev/null.

In reply to wz z

Re: How to print or save internal detail of an object?

by Richard Jones -
Picture of Plugin developers Picture of Testers

var_dump($eventdata) will also work, add an exit command if you need the process to halt to allow you to view it.

In reply to Richard Jones

Re: How to print or save internal detail of an object?

by wz z -

I tried print_r($var, true), it works. But unfortunately, Apache errolog truncated the $eventdata variable, I cannot view all its internal detail. 

Could you tell me the exact exit command in Moodle, please?

In reply to wz z

Re: How to print or save internal detail of an object?

by Conn Warwicker -
Picture of Core developers Picture of Plugin developers

It might be easier to just log the contents to a different file.


You can write a simple function for that, e.g.




function mylog($value)

{

    global $CFG;

    $file = fopen($CFG->dataroot . '/myfile.txt', 'a');

    if ($file){

        fwrite($file, print_r($value, true));

        fwrite($file, "\n");

        fclose($file);

    }

}


Then just call it with: mylog($eventdata)





In reply to Conn Warwicker

Re: How to print or save internal detail of an object?

by wz z -

Thank you, it works!