drhzn3911 2016-04-07 23:52
浏览 836
已采纳

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 23: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条)

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置