General developer forum

How to print or save internal detail of an object?

 
Picture of wz z
How to print or save internal detail of an object?
 

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: -
Tim at Lone Pine Koala Sanctuary
Re: How to print or save internal detail of an object?
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

Just do

print_object($eventdata);


 
Average of ratings: -
Picture of wz z
Re: How to print or save internal detail of an object?
 

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.

 
Average of ratings: -
Picture of Conn Warwicker
Re: How to print or save internal detail of an object?
Core developersParticularly helpful MoodlersPlugin developers

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

 
Average of ratings: Useful (1)
Picture of Andrew Nicols
Re: How to print or save internal detail of an object?
Core developersMoodle HQParticularly helpful MoodlersPlugin developersTesters

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

 
Average of ratings: -
Richard Jones
Re: How to print or save internal detail of an object?
Particularly helpful MoodlersPlugin developersTesters

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

 
Average of ratings: -
Picture of wz z
Re: How to print or save internal detail of an object?
 

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?

 
Average of ratings: -
Picture of Conn Warwicker
Re: How to print or save internal detail of an object?
Core developersParticularly helpful MoodlersPlugin 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)





 
Average of ratings: -
Picture of wz z
Re: How to print or save internal detail of an object?
 

Thank you, it works!

 
Average of ratings: -