Yii Framework Forum: HeadersAlreadySentException - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic


#1 User is offline   scottix 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 32
  • Joined: 16-November 12

Posted 01 March 2018 - 04:49 PM


I am trying to understand why this was a bug and why throwing an Exception is a good idea.

I agree it is not best to send headers again and in the previous version it just failed silently, which I think is the proper thing to do. Now starting in 2.0.14 it is throwing an ErrorException even though everything could be ok.

Couldn't we just create a log entry or something instead of completely error-ing and breaking anything that didn't use Yii's Response.

Could say something like "[Warning] yii\web\Response - Headers already sent"

#2 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 3,612
  • Joined: 16-February 11
  • Location:Japan

Posted 02 March 2018 - 07:53 PM

Hi scottix,

It looks to me a good decision of the developers to throw the exception. Every error should be promptly revealed. IMO "silent failure" is the worst kind of behavior in the framework which will disturb us in developing/debugging an app.

#3 User is offline   Roberto Braga 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 216
  • Joined: 18-February 13
  • Location:Roma, Italy

Posted 03 March 2018 - 01:54 AM

If you it is your intention to send again the header just do a try catch and manage the exception. So it is clear at code level that this is the intended behavior.

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users