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.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...