How to print or save internal detail of an object?

How to print or save internal detail of an object?

per wz z -
Nombre de respostes: 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 Trist

Mitjana de qualificacions: -
En resposta a wz z

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

per Tim Hunt -
Imatge Core developers Imatge Documentation writers Imatge Particularly helpful Moodlers Imatge Peer reviewers Imatge Plugin developers

Just do

print_object($eventdata);


En resposta a Tim Hunt

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

per 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.

En resposta a wz z

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

per Richard Jones -
Imatge Plugin developers Imatge Testers

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

En resposta a Richard Jones

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

per 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?

En resposta a wz z

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

per Conn Warwicker -
Imatge Core developers Imatge 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)