I have found 2 ways of printing an object, either directly in the browser or in a log file in case nothing shows up on your page.
Directly in the browser:
print_r(json_encode($object->getData()));
As in my case using XDebug is not always possible (constraints from how things were setup here before), I created a log file to track my variables' values. Although it's clearly not best practise, but if you don't have a choice this can help out.
Debugging log file function:
function debugging_log($log_msg)
{
$log_filename = "{path_to_your_log_file}/debugging.log";
$log_file_data = '[' . date('Y/m/d H:i:s') . ']' . ' ' . $log_msg;
file_put_contents($log_filename, $log_file_data . "\n", FILE_APPEND);
}
Same as for the print_r()
, you pass a json object to the function like this:
debugging_log(json_encode($object->getData()));
It prints messages like this in the case of an object:
[2020/10/07 04:45:23] {"id":"5","key_1":"Title 1","key_2":"122","created_at":"2020-10-05 09:34:53"}
Hope this helps!