View Issue Details

IDProjectCategoryView StatusLast Update
0000665XdebugUncategorizedpublic2020-03-12 17:16
Reporterdangerousben Assigned Toderick  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product Version2.2dev 
Summary0000665: xdebug does not respect display_errors=stderr
Description

Since PHP 5.2.4, it has been possible to set display_errors=stderr to send errors to stderr rather than stdout. xdebug does not respect this setting.

Steps To Reproduce

Enable xdebug, set display_errors=stderr, run some PHP code that generates an error. The error goes to stdout.

TagsNo tags attached.
Attached Files
stderr.diff (3,071 bytes)   
Index: xdebug_stack.c
===================================================================
--- xdebug_stack.c	(revision 3392)
+++ xdebug_stack.c	(working copy)
@@ -470,6 +470,17 @@
 	}
 }
 
+static void output_error(const char *error)
+{
+#ifdef PHP_DISPLAY_ERRORS_STDERR
+	if (PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR) {
+		fputs(error, stderr);
+		fflush(stderr);
+		return;
+	}
+#endif
+	php_printf("%s", error);
+}
 
 /* Error callback for formatting stack traces */
 void xdebug_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
@@ -570,13 +581,13 @@
 				xdebug_append_printable_stack(&str, PG(html_errors) TSRMLS_CC);
 				xdebug_str_add(&str, XG(last_exception_trace), 0);
 				xdebug_append_error_footer(&str, PG(html_errors) TSRMLS_CC);
-				php_printf("%s", str.d);
+				output_error(str.d);
 
 				xdfree(str.d);
 				free(tmp_buf);
 			} else {
 				printable_stack = get_printable_stack(PG(html_errors), error_type_str, buffer, error_filename, error_lineno TSRMLS_CC);
-				php_printf("%s", printable_stack);
+				output_error(printable_stack);
 				xdfree(printable_stack);
 			}
 		}
Index: tests/bug00665.phpt
===================================================================
--- tests/bug00665.phpt	(revision 0)
+++ tests/bug00665.phpt	(revision 0)
@@ -0,0 +1,49 @@
+--TEST--
+Test for bug #: xdebug does not respect display_errors=stderr
+--SKIPIF--
+<?php if (!extension_loaded("xdebug")) die("skip xdebug required"); ?>
+<?php if (version_compare(phpversion(), "5.2.4", '<')) die("skip display_errors=stderr only supported since PHP 5.2.4"); ?>
+--FILE--
+<?php
+$php = getenv('TEST_PHP_EXECUTABLE') . ' -d log_errors=Off -d xdebug.default_enable=On';
+
+$error = '-r ' . escapeshellarg('trigger_error("PASS");');
+$exception = '-r ' . escapeshellarg('throw new Exception("PASS");');
+
+$errors_stdout = '-d display_errors=On';
+$errors_stderr = '-d display_errors=stderr';
+$errors_nowhere = '-d display_errors=Off';
+
+$null = substr(PHP_OS, 0, 3) == 'WIN' ? 'NUL' : '/dev/null';
+$output_stdout = "2>$null";
+$output_stderr = "2>&1 >$null";
+
+if (`$php $error $errors_stdout $output_stdout`) echo "PASS1\n";
+if (!`$php $error $errors_stderr $output_stdout`) echo "PASS2\n";
+if (!`$php $error $errors_nowhere $output_stdout`) echo "PASS3\n";
+
+if (!`$php $error $errors_stdout $output_stderr`) echo "PASS4\n";
+if (`$php $error $errors_stderr $output_stderr`) echo "PASS5\n";
+if (!`$php $error $errors_nowhere $output_stderr`) echo "PASS6\n";
+
+if (`$php $exception $errors_stdout $output_stdout`) echo "PASS7\n";
+if (!`$php $exception $errors_stderr $output_stdout`) echo "PASS8\n";
+if (!`$php $exception $errors_nowhere $output_stdout`) echo "PASS9\n";
+
+if (!`$php $exception $errors_stdout $output_stderr`) echo "PASS10\n";
+if (`$php $exception $errors_stderr $output_stderr`) echo "PASS11\n";
+if (!`$php $exception $errors_nowhere $output_stderr`) echo "PASS12\n";
+?>
+--EXPECT--
+PASS1
+PASS2
+PASS3
+PASS4
+PASS5
+PASS6
+PASS7
+PASS8
+PASS9
+PASS10
+PASS11
+PASS12
stderr.diff (3,071 bytes)   
Operating System
PHP Version5.3.3

Relationships

has duplicate 0001033 resolvedderick Show PHP errors during debugging as they happen (by supporting stderr) 

Activities

dangerousben

2011-02-13 17:04

reporter   ~0001675

Patch attached.

derick

2011-02-21 22:13

administrator   ~0001680

Fixed in SVN. Much thanks for the patch!

Issue History

Date Modified Username Field Change
2011-02-13 17:02 dangerousben New Issue
2011-02-13 17:04 dangerousben File Added: stderr.diff
2011-02-13 17:04 dangerousben Note Added: 0001675
2011-02-21 22:13 derick Note Added: 0001680
2011-02-21 22:13 derick Status new => closed
2011-02-21 22:13 derick Assigned To => derick
2011-02-21 22:13 derick Resolution open => fixed
2016-12-11 13:05 derick Relationship added has duplicate 0001033
2020-03-12 16:55 derick Severity minor => feature
2020-03-12 17:16 derick Category Feature/Change request => Uncategorized