-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Bug: CodeIgniter\Debug\Exceptions::exceptionHandler() sending header causes error if headers already sent #5679
Comments
I tried Steps to Reproduce, but I see only "Some output". No errors in the web page.
Why? |
By the way, I recommend not use |
Only using echo and setcookie() to demonstrate.
Ok, my bad, it doesn't put out the error, however it doesn't attempt to render the error page. Maybe this is ok.. but it would be nice to render the page if possible. You would have any output before the page render though. Same with the debug page. Also, it still sets another error: Cannot modify header information - headers already sent in /system/Debug/Exceptions.php:xxx Its clear that in the event that headers have been sent then the exception handler is going to cause an exception. I think it makes sense to suppress this in this particular case.
If you have already begun output and headers have been sent then you can't set a cookie. I'm not having any particular issue but in the course of testing some things I've discovered that the exception handler breaks if headers have been sent and an exception occurs. |
Your example is not realistic. I think you just wrote incorrect code.
You should not output anything by yourself. The Response object does. And I think if there are two errors, it should be shown or logged as it is.
You had the error "Cannot modify header information", and you did not catch the error, |
the only unhandled error is the one from the call to header() when headers have been sent. |
@sclubricants please mind your language. As with other OSS, please abide by the code of conduct of this repo. |
Okay, I got your point. |
PHP Version
8.0
CodeIgniter4 Version
4.1.8
CodeIgniter4 Installation Method
Composer (using
codeigniter4/appstarter
)Which operating systems have you tested for this bug?
Windows
Which server did you use?
apache
Database
No response
What happened?
If for some reason the application has already sent headers it causes another error in the exception handler and fails to properly handle this circumstance. This allows php to output error in production environment.
Steps to Reproduce
In a controller add the following lines:
Expected Output
It is expected to receive an error that you cannot modify headers because they are already sent.
However if in production or development environments the error is dumped by php as well as an additional similar error caused in the call to header() in CodeIgniter\Debug\Exceptions::exceptionHandler()
The screen as well as log files show:
Anything else?
Its a messy situation I know.. Not sure the best way to handle it. If we suppress the second error by using @Header() at least the page will continue to render in development and in production will render error page instead of outputting errors.
Then our log outputs only the first error:
The text was updated successfully, but these errors were encountered: