Closed wirwolf closed 4 years ago
How to reproduce it?
$tmp = \Yii::$app->response;
$tmp->format = Response::FORMAT_JSON;
$arr = [
'1' =>
[
'2' =>
[
],
'3' =>
[
]
]
];
$arr['1']['2'] = &$arr['1'];
$tmp->data = $arr;
$tmp->send();
this bug in FORMAT_JSON and FORMAT_XML
How would expect such array to be formatted in JSON or XML?
It is recursive and both formats could not represent it.
how to convert error exeption trace to json?
Which error exception? Usually trace doesn't contain any recursion.
Hi. I also have this bug occurs config
'log' => [ 'traceLevel' => 0, 'flushInterval' => 1, 'targets' => [ [ 'class' => 'yii\log\FileTarget', 'levels' => ['error', 'warning'], 'logVars' => [null], 'exportInterval' => 1, 'logFile' => '@app/runtime/logs/error.log', ], ], ],
for example usage
public function actionIndex() { Yii::error("My error message"); }
in log file
2015-11-10 07:50:28 [127.0.0.1][-][-][error][application] My error message 2015-11-10 07:50:28 [127.0.0.1][-][-][error][application] My error message
the same occurs for Exception
for example usage
public function actionIndex() { throw new HttpException(404, 'Error message'); }
in log file
2015-11-10 08:06:06 [127.0.0.1][-][-][error][yii\web\HttpException:404] exception 'yii\web\HttpException' with message 'Error message' in /var/www/components/controllers/SiteController.php:54 Stack trace: #0 [internal function]: app\controllers\SiteController->actionIndex() yiisoft/yii-core#1 /var/www/components/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array) yiisoft/yii-core#2 /var/www/components/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array) yiisoft/yii-core#3 /var/www/components/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('index', Array) yiisoft/yii-core#4 /var/www/components/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('site/index', Array) yiisoft/yii-core#5 /var/www/components/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request)) yiisoft/yii-core#6 /var/www/components/web/index.php(12): yii\base\Application->run() yiisoft/yii-core#7 {main} 2015-11-10 08:06:07 [127.0.0.1][-][-][error][yii\web\HttpException:404] exception 'yii\web\HttpException' with message 'Error message' in /var/www/components/controllers/SiteController.php:54 Stack trace: #0 [internal function]: app\controllers\SiteController->actionIndex() yiisoft/yii-core#1 /var/www/components/vendor/yiisoft/yii2/base/InlineAction.php(55): call_user_func_array(Array, Array) yiisoft/yii-core#2 /var/www/components/vendor/yiisoft/yii2/base/Controller.php(151): yii\base\InlineAction->runWithParams(Array) yiisoft/yii-core#3 /var/www/components/vendor/yiisoft/yii2/base/Module.php(455): yii\base\Controller->runAction('index', Array) yiisoft/yii-core#4 /var/www/components/vendor/yiisoft/yii2/web/Application.php(84): yii\base\Module->runAction('site/index', Array) yiisoft/yii-core#5 /var/www/components/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request)) yiisoft/yii-core#6 /var/www/components/web/index.php(12): yii\base\Application->run() yiisoft/yii-core#7 {main}
debugging
vendor/yiisoft/yii2/log/Logger.php
public function flush($final = false) { $messages = $this->messages; var_dump($messages); exit; // https://github.com/yiisoft/yii2/issues/5619 // new messages could be logged while the existing ones are being handled by targets $this->messages = []; if ($this->dispatcher instanceof Dispatcher) { $this->dispatcher->dispatch($messages, $final); } }
return http://joxi.ru/VrwqpZVcZBL82X
or in vendor/yiisoft/yii2/log/Dispatcher.php
public function dispatch($messages, $final) { var_dump($messages); exit; $targetErrors = []; foreach ($this->targets as $target) { if ($target->enabled) { try { $target->collect($messages, $final); } catch (\Exception $e) { $target->enabled = false; $targetErrors[] = [ 'Unable to send log via ' . get_class($target) . ': ' . ErrorHandler::convertExceptionToString($e), Logger::LEVEL_WARNING, __METHOD__, microtime(true), [], ]; } } } if (!empty($targetErrors)) { $this->dispatch($targetErrors, true); } }
There's an option JSON_PARTIAL_OUTPUT_ON_ERROR for json_encode() which sets NULL instead of recursive references, see http://php.net/manual/en/json.constants.php
Since 5.5.0. We support 5.4.
PHP 5.4 is outdated since 2015-09-14 and won't even get any security updates. Minimum requirement should be set to 5.6: http://php.net/supported-versions.php
In the next major version — certainly.
It's now solved as we're requiring 7.4.