Skip to content

Commit

Permalink
Fixes yiisoft#15046: Throw an yii\web\HeadersAlreadySentException i…
Browse files Browse the repository at this point in the history
…f headers were sent before web response
  • Loading branch information
dmirogin authored and samdark committed Dec 19, 2017
1 parent 315855f commit 28e7f31
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Yii Framework 2 Change Log
2.0.14 under development
------------------------

- Bug #15046: Throw an `yii\web\HeadersAlreadySentException` if headers were sent before web response (dmirogin)
- Enh #3087: Added `yii\helpers\BaseHtml::error()` "errorMethod" option to be able to customize errors display (yanggs07, developeruz)
- Bug #15355: Fixed `yii\db\Query::from()` does not work with `yii\db\Expression` (vladis84)
- Bug #8983: Only truncate the original log file for rotation (matthewyang, developeruz)
Expand Down
29 changes: 29 additions & 0 deletions framework/web/HeadersAlreadySentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yii\web;

use yii\base\Exception;

/**
* HeadersAlreadySentException represents an exception caused by
* any headers that were already sent before web response was sent.
*
* @author Dmitry Dorogin <[email protected]>
* @since 2.0.14
*/
class HeadersAlreadySentException extends Exception
{
/**
* @inheritdoc
*/
public function __construct($file, $line)
{
$message = YII_DEBUG ? "Headers already sent in {$file} on line {$line}." : 'Headers already sent.';
parent::__construct($message);
}
}
4 changes: 2 additions & 2 deletions framework/web/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ public function clear()
*/
protected function sendHeaders()
{
if (headers_sent()) {
return;
if (headers_sent($file, $line)) {
throw new HeadersAlreadySentException($file, $line);
}
if ($this->_headers) {
$headers = $this->getHeaders();
Expand Down

0 comments on commit 28e7f31

Please sign in to comment.