View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 394 | Exception_DefaultHandler | All | public | 4 Nov 2011 11:08 | 27 Feb 2012 21:29 |
| Reporter | mrosenquist | Assigned To | timj | ||
| Priority | normal | Severity | crash | Reproducibility | have not tried |
| Status | closed | Resolution | fixed | ||
| Product Version | 0.8.1 | ||||
| Target Version | 0.8.2 | Fixed in Version | 0.8.2 | ||
| Summary | 394: Notice error when showing an error on a page when the content type has been set to other than text/html | ||||
| Description | When ErrorHandler is used on a page which sets a content-type header other than "text/html" and an error occurs the output is written to STDERR | ||||
| Steps To Reproduce | <?php // Page served via web require_once 'Exception/DefaultHandler.php'; // Handle normal exceptions/errors set_exception_handler(array('Exception_DefaultHandler', 'handleException')); set_error_handler(array('Exception_DefaultHandler', 'handleError')); header('Content-type: application/xml'); // Create a simple error echo $foo; | ||||
| Additional Information | Gernerated Error: =============== Notice: Use of undefined constant STDERR - assumed 'STDERR' in /Users/mattrq/Work/Dropbox/XDEV_Library/Exception_DefaultHandler/DefaultHandler.php on line 259 Warning: fwrite(): supplied argument is not a valid stream resource in /Users/mattrq/Work/Dropbox/XDEV_Library/Exception_DefaultHandler/DefaultHandler.php on line 259 | ||||
| Tags | No tags attached. | ||||
| Attached Files | DefaultHandler.php.bug394.patch (531 bytes)
Index: DefaultHandler.php
===================================================================
--- DefaultHandler.php (revision 50386)
+++ DefaultHandler.php (working copy)
@@ -249,7 +249,11 @@
print "<pre style='text-align:left;'>" . nl2br(htmlspecialchars($backtrace, ENT_QUOTES)) . '</pre>';
} else {
$output = "$errtype: $errmsg in $filename on line $linenum\n\n" . $backtrace;
- fwrite(STDERR, $output);
+ if (PHP_SAPI == 'cli') {
+ fwrite(STDERR, $output);
+ } else {
+ print $output;
+ }
}
}
| ||||
|
|
A possible fix has been attached, it is not the most elegant fix but it will work |
|
|
Thanks for the report! Actually the bug is with the use of STDERR - fwrite(STDERR, 'foo') is just bad code - it's not the context (CLI or otherwise) that it is called from. But anyway I think the logic would be better like this - what do you think? if (output_is_html) { show_html_page_on_normal_output } else if (running_from_cli) { write_to_stderr // the correct way ;-) } else { write_plain_text_to_normal_output } |
|
|
The fix you suggest looks much better. |
|
|
(Info) The error may not be seen when using a normal web browser, but this may help to reproduce: curl -H 'Accept: image/foo' http://server/test.php |
|
|
Fixed in SVN r2247 |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 4 Nov 2011 11:08 | mrosenquist | New Issue | |
| 4 Nov 2011 11:13 | mrosenquist | File Added: DefaultHandler.php.bug394.patch | |
| 4 Nov 2011 11:14 | mrosenquist | Note Added: 399 | |
| 4 Nov 2011 17:26 | timj | Note Added: 400 | |
| 4 Nov 2011 17:26 | timj | Assigned To | => timj |
| 4 Nov 2011 17:26 | timj | Status | new => assigned |
| 4 Nov 2011 17:26 | timj | Product Version | => 0.8.1 |
| 4 Nov 2011 17:26 | timj | Target Version | => 0.8.2 |
| 4 Nov 2011 19:06 | mrosenquist | Note Added: 401 | |
| 5 Nov 2011 22:45 | timj | Note Added: 404 | |
| 5 Nov 2011 22:46 | timj | Note Added: 405 | |
| 5 Nov 2011 22:46 | timj | Status | assigned => resolved |
| 5 Nov 2011 22:46 | timj | Resolution | open => fixed |
| 5 Nov 2011 22:46 | timj | Fixed in Version | => 0.8.2 |
| 27 Feb 2012 21:29 | timj | Status | resolved => closed |