Php 无法将对象转换为字符串

Php 无法将对象转换为字符串,php,Php,因此,我尝试将此代码日志设置为异常,但它给了我一个错误消息,类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[

因此,我尝试将此代码日志设置为异常,但它给了我一个错误消息,类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']不起作用,仍然会给我同样的错误。关于如何将其转换为字符串,还有其他解决方案吗


我已经看了他们建议怎么做了

哪个var有类domain\u model的对象?据我所知,应该是$exception\u obj->getMessage(),因为它甚至在函数中被称为string。不幸的是,从一开始就不是我写的代码,我没有办法联系这样做的人,我只写了我确定的东西。我可能会补充说,这应该记录一个错误,或者在本例中是一个异常,但由于这个问题,它不会记录。为了避免这个问题,您需要将uu toString()方法添加到$t['object'];或者使用print_r($t['object'],true)或者serialize($t['object'])将对象转换为string谢谢,我会尽快对其进行测试,如果我没有完全错的话,就不需要使用isset语句,因为这会检查它是否为null。