I'm fairly new to PHP, so forgive me if there's an easy answer to this. I've searched for any similar questions in stackoverflow, but couldn't find any help.
I'm working on an existing php-based application, and I simply need to be able to print the contents of objects and arrays to either a log or console for debugging. The catch is that the function isn't directly called by the client, but rather pulls MySQL data, modifies it, and returns the data. This means options like Chrome Logger (https://craig.is/writing/chrome-logger) and using console.log() in javascript do not show up in the console.
The application I'm working for has a simple logging function, but it only accepts strings. I am unable to modify the log function, and as such am having trouble printing objects and arrays of which I have no idea what the contents are.
Does anyone have any advice as to how to proceed in this matter?
In particular, I'm trying to find the results of the MySQL query, so if there's a workaround to obtain that data, that would would work as well.
Thanks a lot in advance!
I think you are looking for http://php.net/manual/en/function.error-log.php or Monolog, but that only solves half of the question. You will also need to serialize the object to something that can be represented in a log. You could use php serialize, json encoide or the __toString method to generate that result. See http://php.net/manual/en/language.oop5.magic.php for magic methods that maybe useful.
Try writing the log to a file on the server itself.
file_put_contents('log.txt', $thelog, FILE_APPEND);
I am using chromelog to console log any var in chrome s dev tools. simple & fast debug anything in PHP.