Req #72572 [Opn]: Error Reporting on Text-based Web Server

From: Date: Wed, 13 Jul 2016 10:55:27 +0000
Subject: Req #72572 [Opn]: Error Reporting on Text-based Web Server
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-202270@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72572&edit=1

 ID:                 72572
 User updated by:    David at Refoua dot me
 Reported by:        David at Refoua dot me
 Summary:            Error Reporting on Text-based Web Server
 Status:             Open
 Type:               Feature/Change Request
 Package:            Unknown/Other Function
 Operating System:   Any
 PHP Version:        7.0.8
 Block user comment: N
 Private report:     N

 New Comment:

@kalle Why would @cmd hate something like this? I think this would be a great feature for us
developers!


Previous Comments:
------------------------------------------------------------------------
[2016-07-13 01:33:50] kalle@php.net

@cmb, we could also (and I know you'll hate me for saying this), implement it as an ini option
to auto detect headers for formatting, thrus disabling it by default to keep BC.

------------------------------------------------------------------------
[2016-07-11 11:20:21] David at Refoua dot me

You are correct, however in my opinion, that should be considered as bad practice.
PHP should still output the appropriate format, as reasonably possible. Obviously not all types can
be covered, but it can handle them much better than current state.

Also, PHP should at least give an option to make whatever it outputs in the text-only or rich HTML
format, in order to override what it has determined by itself.
For example, this can make outputting HTML from cli, perhaps by calling a function like: void
set_output_format( int PHP_FORMAT_TEXT | PHP_FORMAT_HTML );
Maybe even automatically setting the Content-Type to text/plain instead of the normal html, if this
function is called in cgi mode and set_output_format() is set to PHP_FORMAT_TEXT.

This would be a really useful feature for developers in my opinion, especially when writing a quick
script in improper environments.

------------------------------------------------------------------------
[2016-07-11 01:14:58] cmb@php.net

Good idea, but I'm afraid that is not generally possible. Consider

  <?php
  ob_start();
  trigger_error(…);
  header('Content-Type: …);
  echo ob_get_clean();

------------------------------------------------------------------------
[2016-07-10 20:47:49] 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 />



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=72572&edit=1


Thread (5 messages)

« previous php.bugs (#202270) next »