Index: main/main.c =================================================================== RCS file: /repository/php-src/main/main.c,v retrieving revision 1.640.2.23.2.47 diff -u -a -r1.640.2.23.2.47 main.c --- main/main.c 21 Jul 2007 01:43:33 -0000 1.640.2.23.2.47 +++ main/main.c 24 Jul 2007 13:22:37 -0000 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: main.c,v 1.640.2.23.2.47 2007/07/21 01:43:33 jani Exp $ */ +/* $Id: main.c,v 1.640.2.23.2.46 2007/07/15 15:34:28 jani Exp $ */ /* {{{ includes */ @@ -213,6 +213,78 @@ } /* }}} */ +/* {{{ php_get_display_errors_mode() helper function + */ +static int php_get_display_errors_mode(char *value, int value_length) +{ + int mode; + + if (value_length == 2 && !strcasecmp("on", value)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else if (value_length == 3 && !strcasecmp("yes", value)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else if (value_length == 4 && !strcasecmp("true", value)) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else if (value_length == 6 && !strcasecmp(value, "stderr")) { + mode = PHP_DISPLAY_ERRORS_STDERR; + } else if (value_length == 6 && !strcasecmp(value, "stdout")) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } else { + mode = atoi(value); + if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) { + mode = PHP_DISPLAY_ERRORS_STDOUT; + } + } + return mode; +} +/* }}} */ + +/* {{{ PHP_INI_MH + */ +static PHP_INI_MH(OnUpdateDisplayErrors) +{ + PG(display_errors) = (zend_bool) php_get_display_errors_mode(new_value, new_value_length); + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_INI_DISP + */ +static PHP_INI_DISP(display_errors_mode) +{ + int mode, tmp_value_length; + char *tmp_value; + + if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { + tmp_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL ); + tmp_value_length = ini_entry->orig_value_length; + } else if (ini_entry->value) { + tmp_value = ini_entry->value; + tmp_value_length = ini_entry->value_length; + } else { + tmp_value = NULL; + tmp_value_length = 0; + } + + mode = php_get_display_errors_mode(tmp_value, tmp_value_length); + + switch (mode) { + case PHP_DISPLAY_ERRORS_STDERR: + PUTS("STDERR"); + break; + + case PHP_DISPLAY_ERRORS_STDOUT: + PUTS("STDOUT"); + break; + + default: + PUTS("Off"); + break; + } +} +/* }}} */ + /* Need to convert to strings and make use of: * PHP_SAFE_MODE * @@ -246,7 +318,7 @@ STD_PHP_INI_BOOLEAN("allow_call_time_pass_reference", "1", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, allow_call_time_pass_reference, zend_compiler_globals, compiler_globals) STD_PHP_INI_BOOLEAN("asp_tags", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, asp_tags, zend_compiler_globals, compiler_globals) - STD_PHP_INI_BOOLEAN("display_errors", "1", PHP_INI_ALL, OnUpdateBool, display_errors, php_core_globals, core_globals) + STD_PHP_INI_ENTRY_EX("display_errors", "1", PHP_INI_ALL, OnUpdateDisplayErrors, display_errors, php_core_globals, core_globals, display_errors_mode) STD_PHP_INI_BOOLEAN("display_startup_errors", "0", PHP_INI_ALL, OnUpdateBool, display_startup_errors, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("enable_dl", "1", PHP_INI_SYSTEM, OnUpdateBool, enable_dl, php_core_globals, core_globals) STD_PHP_INI_BOOLEAN("expose_php", "1", PHP_INI_SYSTEM, OnUpdateBool, expose_php, php_core_globals, core_globals) @@ -809,7 +881,14 @@ php_printf("%s
\n%s: %s in %s on line %d
\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); } } else { - php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + /* Write CLI/CGI errors to stderr if display_errors = stderr */ + if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi")) && + PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR + ) { + fprintf(stderr, "%s: %s in %s on line %d\n", error_type_str, buffer, error_filename, error_lineno); + } else { + php_printf("%s\n%s: %s in %s on line %d\n%s", STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string)); + } } } } Index: main/php_globals.h =================================================================== RCS file: /repository/php-src/main/php_globals.h,v retrieving revision 1.98.2.1.2.6 diff -u -a -r1.98.2.1.2.6 php_globals.h --- main/php_globals.h 9 Jul 2007 17:27:23 -0000 1.98.2.1.2.6 +++ main/php_globals.h 24 Jul 2007 13:22:37 -0000 @@ -33,7 +33,11 @@ extern ZEND_API struct _php_core_globals core_globals; #endif +/* Error display modes */ +#define PHP_DISPLAY_ERRORS_STDOUT 1 +#define PHP_DISPLAY_ERRORS_STDERR 2 +/* Track vars */ #define TRACK_VARS_POST 0 #define TRACK_VARS_GET 1 #define TRACK_VARS_COOKIE 2