所以我试图让这个代码日志成为异常,但是它给了我类domain_model的错误消息对象无法转换为字符串
该功能如下:
function errorLog($log, $error_type, $string, $file, $row, $error_hash, $error_trace)
{
$text = $error_hash . ' (' . date('Y-m-d H:i') . "):\n[Error type]: " . $error_type . "\n[Message]: " . $string . "\n[File]: " . $file . "\n[Row]: " . $row . "\n";
$text .= "[Trace]:\n";
foreach ($error_trace as $t)
{
$text .= ((isset($t['type']) && isset($t['object'])) ? $t['object'] . $t['type'] . $t['function'] : $t['function']) . "\n";
$text .= $t['file'] . "\n";
$text .= $t['line'] . "\n";
$text .= print_r($t['file'], 1) . "\n";
}
file_put_contents(BASE . $log . '.log', $text, FILE_APPEND);
}
经过多次思考后,最终看到制造混乱的界限实际上是这样的:
$text .= ((isset($t['type']) && isset($t['object'])) ? $t['object'] . $t['type'] . $t['function'] : $t['function']) . "\n";
正如我所看到的,唯一需要转换的应该是$ t ['object']但是使用(字符串)$ t ['object']不起作用并且仍然给我同样的错误。关于如何将其转换为字符串,还有其他解决方案吗?
我看过他们建议如何完成here