Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dmirogin committed Dec 19, 2017
1 parent f6b2d4d commit d26bce8
Show file tree
Hide file tree
Showing 3 changed files with 36 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
------------------------

- Enh #15046: Throw an `yii\web\HeadersAlreadySentException` if headers were sent before web response
- 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)
- Bug #14276: Fixed I18N format with dotted parameters (developeruz)
Expand Down
33 changes: 33 additions & 0 deletions framework/web/HeadersAlreadySentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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 <dmirogin@ya.ru>
* @since 2.0.14
*/
class HeadersAlreadySentException extends Exception
{
/**
* Create instance of exception depending on debug mode.
*
* @param string $file
* @param int $line
* @return HeadersAlreadySentException
*/
public static function make($file, $line)
{
$message = YII_DEBUG ? "Headers already sent in {$file} on line {$line}." : 'Headers already sent.';
return new static($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 HeadersAlreadySentException::make($file, $line);
}
if ($this->_headers) {
$headers = $this->getHeaders();
Expand Down

0 comments on commit d26bce8

Please sign in to comment.