Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw an Exception when the header is already been sent #3998

Closed
wants to merge 3 commits into from

Conversation

xinquanatcolezhu
Copy link

Please see the details of the discussion at issue #3990

@markstory markstory added this to the 2.5.3 milestone Jul 17, 2014
}
} else {
throw new Exception("Headers already sent in $filename on line $linenum\n");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you are using spaces for indenting. CakePHP uses tabs. I can fix that up if you get stuck on it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please help. I don't know what I am supposed to do? do I need to create a new pull request if Travis fails?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xinquanatcolezhu No. Just make the required change and make a new commit locally. Then push your updates to your github branch and this pull request will be automatically updated.

Please check the github help if you need more details.

@markstory markstory mentioned this pull request Jul 18, 2014
@@ -517,15 +517,20 @@ protected function _setContentLength() {
* @param string $name the header name
* @param string $value the header value
* @return void
* @throws CakeException When an header already been sent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"When a header has already been sent"

@markstory markstory modified the milestones: 2.5.4, 2.5.3 Jul 21, 2014
@davidsteinsland
Copy link
Contributor

I am just a bit curious: In the discussion, it's mentioned that @xinquanatcolezhu is new to CakePHP. This raises a question: Is he doing something wrong?

It sounds like he's using echo's and print's, when he should let CakePHP do the rendering.

Also: The exception should be thrown no matter what. Don't bother checking "if (Configure::read('debug'))": when debug is 0, nothing will be logged or displayed. The ExceptionHandler will do the necessary debug checks.

And as a last tip, I'd prefer:

if (headers_sent()) {
    // throw here
}

// send headers here

There's no need for an else block …

@markstory markstory self-assigned this Jul 28, 2014
@markstory
Copy link
Member

@davidsteinsland Good point, I can clean this up and get it merged in as I see the additional errors being useful for new developers.

@dereuromark
Copy link
Member

@davidsteinsland "Bail early" is exactly what I mentioned in #3998 (comment) ;)

Sounds good. We can probably throw the exception even with debug 0 as right now it would be a no-op either way.

markstory added a commit that referenced this pull request Jul 29, 2014
* Fix the various PHPCS errors.
* Make the logic less complex.
@markstory
Copy link
Member

Closing in favor of #4106

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants