Hi,
while developping some shell scripts with PHP-cli I've got annoyed that PHP
sends its error messages to STDOUT instead of STDERR so I've written the
attached patch.
I see two possible problems with this patch where I'm not sure if one of the
is really critical:
- it uses the PHP STDERR constant defined by PHP-cli. If one doesn't use
PHP-cli and defines a constant with this name which is not a stream-resource
PHP segfaults. (How do I check wether a resource is a stream-resource?)
- there are a few tests checking for error messages and at least
ext/standard/tests/file/userstreams.phpt failed for me after applying this
patch but other tests testing for error messages worked and I'm not sure why
they behave different. (some I/O-Buffers?)
The patch was developped and tested on my i686-pc-linux-gnu box against HEAD.
johannes
PS: The PHP version of HEAD is still 5.0.1-dev but should be 5.1.0-dev, since
5.0.1 is afaik developped in the PHP_5_0 branch. I also added a patch to
update these numbers.
Index: main/php_version.h
===================================================================
RCS file: /repository/php-src/main/php_version.h,v
retrieving revision 1.97
diff -u -r1.97 php_version.h
--- main/php_version.h 13 Jul 2004 19:56:49 -0000 1.97
+++ main/php_version.h 17 Jul 2004 23:22:22 -0000
@@ -1,7 +1,7 @@
/* automatically generated by configure */
/* edit configure.in to change version number */
#define PHP_MAJOR_VERSION 5
-#define PHP_MINOR_VERSION 0
-#define PHP_RELEASE_VERSION 1
+#define PHP_MINOR_VERSION 1
+#define PHP_RELEASE_VERSION 0
#define PHP_EXTRA_VERSION "-dev"
-#define PHP_VERSION "5.0.1-dev"
+#define PHP_VERSION "5.1.0-dev"
Index: configure.in
===================================================================
RCS file: /repository/php-src/configure.in,v
retrieving revision 1.514
diff -u -r1.514 configure.in
--- configure.in 13 Jul 2004 19:56:48 -0000 1.514
+++ configure.in 17 Jul 2004 23:22:23 -0000
@@ -39,8 +39,8 @@
AC_CONFIG_HEADER(main/php_config.h)
MAJOR_VERSION=5
-MINOR_VERSION=0
-RELEASE_VERSION=1
+MINOR_VERSION=1
+RELEASE_VERSION=0
EXTRA_VERSION="-dev"
VERSION="$MAJOR_VERSION.$MINOR_VERSION.$RELEASE_VERSION$EXTRA_VERSION"
Index: Zend/zend.h
===================================================================
RCS file: /repository/ZendEngine2/zend.h,v
retrieving revision 1.257
diff -u -r1.257 zend.h
--- Zend/zend.h 13 Jul 2004 19:56:49 -0000 1.257
+++ Zend/zend.h 17 Jul 2004 23:22:24 -0000
@@ -22,7 +22,7 @@
#ifndef ZEND_H
#define ZEND_H
-#define ZEND_VERSION "2.0.1-dev"
+#define ZEND_VERSION "2.1.0-dev"
#define ZEND_ENGINE_2
Index: main/main.c
===================================================================
RCS file: /repository/php-src/main/main.c,v
retrieving revision 1.605
diff -u -r1.605 main.c
--- main/main.c 15 Jul 2004 22:22:06 -0000 1.605
+++ main/main.c 18 Jul 2004 00:01:36 -0000
@@ -735,7 +735,25 @@
char *error_format = PG(html_errors) ?
"%s<br />\n<b>%s</b>: %s in <b>%s</b> on line
<b>%d</b><br />\n%s"
: "%s\n%s: %s in %s on line %d\n%s";
- php_printf(error_format, STR_PRINT(prepend_string),
error_type_str, buffer, error_filename, error_lineno, STR_PRINT(append_string));
+ zval *z_stderr = emalloc(sizeof(zval));
+
+ if (zend_get_constant("STDERR", sizeof("STDERR")-1,
z_stderr TSRMLS_DC) && IS_RESOURCE == Z_TYPE_P(z_stderr)) {
+ php_stream *err_stream;
+ char *error_msg;
+ int msg_len;
+ zval *return_value; /* php_stream_from_zval
needs this */
+
+ php_stream_from_zval(err_stream, &z_stderr);
+
+ msg_len = spprintf(&error_msg, 0,
error_format, STR_PRINT(prepend_string), error_type_str, buffer, error_filename,
error_lineno, STR_PRINT(append_string));
+ php_stream_write(err_stream, error_msg,
msg_len);
+
+ efree(error_msg);
+ } else {
+ php_printf(error_format,
STR_PRINT(prepend_string), error_type_str, buffer, error_filename, error_lineno,
STR_PRINT(append_string));
+ }
+
+ efree(z_stderr);
}
}
#if ZEND_DEBUG
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php