Commit a9e71d55 by Qiang Xue

better handling with exceptions in __toString()

parent 528f8c82
......@@ -781,7 +781,7 @@ class Response extends \yii\base\Response
if (is_array($this->content)) {
$this->content = 'array()';
} elseif (is_object($this->content)) {
$this->content = method_exists($this->content, '__toString') ? (string)$this->content : get_class($this->content);
$this->content = method_exists($this->content, '__toString') ? $this->content->__toString() : get_class($this->content);
}
}
}
......@@ -128,7 +128,14 @@ class ActiveField extends Component
*/
public function __toString()
{
return $this->render();
// __toString cannot throw exception
// use trigger_error to bypass this limitation
try {
return $this->render();
} catch (\Exception $e) {
trigger_error($e->getMessage());
return '';
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment