Browse Source

better handling with exceptions in __toString()

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
a9e71d5565
  1. 2
      framework/yii/web/Response.php
  2. 7
      framework/yii/widgets/ActiveField.php

2
framework/yii/web/Response.php

@ -781,7 +781,7 @@ class Response extends \yii\base\Response
if (is_array($this->content)) { if (is_array($this->content)) {
$this->content = 'array()'; $this->content = 'array()';
} elseif (is_object($this->content)) { } 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);
} }
} }
} }

7
framework/yii/widgets/ActiveField.php

@ -128,7 +128,14 @@ class ActiveField extends Component
*/ */
public function __toString() public function __toString()
{ {
// __toString cannot throw exception
// use trigger_error to bypass this limitation
try {
return $this->render(); return $this->render();
} catch (\Exception $e) {
trigger_error($e->getMessage());
return '';
}
} }
/** /**

Loading…
Cancel
Save