微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 如何在Yii中转储变量以进行调试?

如何在Yii中转储和打印变量以进行调试?我想使用var_dump()或print_r().我试图使用Yii :: trace()但它在runtime / logs / app.log中崩溃了这个错误.它甚至没有告诉我代码中的行失败.
2015-03-18 20:54:11 [::1][-][-][warning][yii\log\dispatcher::dispatch] Unable to send log via yii\debug\LogTarget: Exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed'

in /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2-debug/LogTarget.PHP:58

Stack trace:
#0 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2-debug/LogTarget.PHP(58): serialize(Array)
#1 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2-debug/LogTarget.PHP(112): yii\debug\LogTarget->export(Array)
#2 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2/log/dispatcher.PHP(183): yii\debug\LogTarget->collect(Array,true)
#3 /cygdrive/c/Users/Chloe/workspace/AffiliateArbitrage/vendor/yiisoft/yii2/log/Logger.PHP(170): yii\log\dispatcher->dispatch(Array,true)
#4 [internal function]: yii\log\Logger->flush(true)
#5 {main}

参考
http://www.yiiframework.com/doc-2.0/guide-runtime-logging.html

因为你问的是像var_dump和print_r这样的东西,我可以为此建议内置帮助器.它被称为 yii\helpers\VarDumper. Yii::trace()用于记录跟踪消息.

VarDumper is intended to replace the buggy PHP function var_dump and print_r.

It can correctly identify the recursively referenced objects in a
complex object structure. It also has a recursive depth control to
avoid indefinite recursive display of some peculiar variables.

VarDumper can be used as follows,

VarDumper::dump($var);

就个人而言,我不使用它,只是尝试了几次进行测试.

我认为最好将Xdebug用于此目的.

另见PsySH.

原文地址:https://www.jb51.cc/php/130873.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐