From 3519c14e60a3e8f15b81811ecd2f95da985d6e38 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 29 Jan 2014 00:59:41 +0100 Subject: [PATCH] throw exceptions in case of invalid response content fixes #1842 --- framework/web/Response.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/framework/web/Response.php b/framework/web/Response.php index 0068afd01a..f84d2a0df2 100644 --- a/framework/web/Response.php +++ b/framework/web/Response.php @@ -870,9 +870,13 @@ class Response extends \yii\base\Response } if (is_array($this->content)) { - $this->content = 'array()'; + throw new InvalidParamException("Response content must not be an array."); } elseif (is_object($this->content)) { - $this->content = method_exists($this->content, '__toString') ? $this->content->__toString() : get_class($this->content); + if (method_exists($this->content, '__toString')) { + $this->content = $this->content->__toString(); + } else { + throw new InvalidParamException("Response content can only be an object when it implements __toString() method."); + } } } }