|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-07-10 20:47 UTC] David at Refoua dot me
Description:
------------
When PHP is used with internal error reporting mechanism, PHP will determine if the error message is printed on a command-line interface, or a Web Server (i.e. cgi). All CLI messages are outputted using the text-only format.
However, this only is desired if the Web Server is only returning a HTML file. PHP should determine the current header, and if Content-Type is set to text/plain, or text/*, or anything that a current modern browser would not interpret as a HTML document, any content produced by HTML should be formatted for a text-only output.
Therefore, PHP's own error reporting should output the same way CLI does, when the header's Content-Type is set to text/plain with PHP.
Test script:
---------------
NOTE: This script is called with cgi from a web server, and not from cli.
<?php
header("Content-Type: text/plain");
abcd(); // An undefined function to produce error
?>
Expected result:
----------------
Fatal error: Uncaught Error: Call to undefined function abcd() in -:1
Stack trace:
#0 {main}
thrown in - on line 1
Actual result:
--------------
<br />
<b>Fatal error</b>: Uncaught Error: Call to undefined function abcd() in -:1
Stack trace:
#0 {main}
thrown in <b>-</b> on line <b>1</b><br />
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 21:00:01 2025 UTC |
Good idea, but I'm afraid that is not generally possible. Consider <?php ob_start(); trigger_error(…); header('Content-Type: …); echo ob_get_clean();