drhzn3911 2016-04-07 15:52
浏览 838
已采纳

PHP - 将对象打印到控制台/日志以获取后端功能

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!

  • 写回答

3条回答 默认 最新

  • dongzhao2725 2016-04-07 15:59
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部