diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php index ac5fc77..bdb9178 100644 --- a/framework/yii/web/Response.php +++ b/framework/yii/web/Response.php @@ -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); } } } diff --git a/framework/yii/widgets/ActiveField.php b/framework/yii/widgets/ActiveField.php index 00a28df..bba1ead 100644 --- a/framework/yii/widgets/ActiveField.php +++ b/framework/yii/widgets/ActiveField.php @@ -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 ''; + } } /**