gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 12:48:23 26 4
gpt4 key购买 nike

如何在 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_dumpprint_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 .

关于php - 如何在 Yii 中转储变量以进行调试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29135485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com