summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeev Suraski <zeev@php.net>2000-02-04 14:54:30 +0000
committerZeev Suraski <zeev@php.net>2000-02-04 14:54:30 +0000
commit8055da983011d27441fd560f39eea9bc0646580b (patch)
tree271815f6c0e72d661f2475504f96de8aa1b0a2e2
parentb6197bcf902373c481eac2c5484954c3b3bd5f85 (diff)
downloadphp-git-8055da983011d27441fd560f39eea9bc0646580b.tar.gz
Use the new state functions
@- If header information is sent after output has already been sent, the warning @ message will now state the filename and line number at which the first output @ was made (Zeev)
-rw-r--r--ext/standard/output.c32
-rw-r--r--ext/standard/php_output.h3
-rw-r--r--main/SAPI.c10
-rw-r--r--main/main.c25
-rw-r--r--main/output.c32
-rw-r--r--main/php_output.h3
6 files changed, 89 insertions, 16 deletions
diff --git a/ext/standard/output.c b/ext/standard/output.c
index f115a7bab6..b7fa6ebca1 100644
--- a/ext/standard/output.c
+++ b/ext/standard/output.c
@@ -46,6 +46,8 @@ typedef struct {
uint ob_block_size;
uint ob_text_length;
unsigned char implicit_flush;
+ char *output_start_filename;
+ int output_start_lineno;
} php_output_globals;
#ifdef ZTS
@@ -79,6 +81,8 @@ static void php_output_init_globals(OLS_D)
OG(ob_block_size) = 0;
OG(ob_text_length) = 0;
OG(implicit_flush) = 0;
+ OG(output_start_filename) = NULL;
+ OG(output_start_lineno) = 0;
}
@@ -342,6 +346,18 @@ static int php_ub_body_write(const char *str, uint str_length)
zend_bailout();
}
if (php_header()) {
+ if (zend_is_compiling()) {
+ CLS_FETCH();
+
+ OG(output_start_filename) = zend_get_compiled_filename(CLS_C);
+ OG(output_start_lineno) = zend_get_compiled_lineno(CLS_C);
+ } else if (zend_is_executing()) {
+ ELS_FETCH();
+
+ OG(output_start_filename) = zend_get_executed_filename(ELS_C);
+ OG(output_start_lineno) = zend_get_executed_lineno(ELS_C);
+ }
+
OG(php_body_write) = php_ub_body_write_no_header;
result = php_ub_body_write_no_header(str, str_length);
}
@@ -409,6 +425,22 @@ PHP_FUNCTION(ob_implicit_flush)
}
+PHPAPI char *php_get_output_start_filename()
+{
+ OLS_FETCH();
+
+ return OG(output_start_filename);
+}
+
+
+PHPAPI int php_get_output_start_lineno()
+{
+ OLS_FETCH();
+
+ return OG(output_start_lineno);
+}
+
+
/*
* Local variables:
diff --git a/ext/standard/php_output.h b/ext/standard/php_output.h
index 17c8424429..95c6c26ede 100644
--- a/ext/standard/php_output.h
+++ b/ext/standard/php_output.h
@@ -30,7 +30,8 @@ PHPAPI void php_end_ob_buffering(int send_buffer);
PHPAPI int php_ob_get_buffer(pval *p);
PHPAPI void php_start_implicit_flush();
PHPAPI void php_end_implicit_flush();
-
+PHPAPI char *php_get_output_start_filename();
+PHPAPI int php_get_output_start_lineno();
extern zend_module_entry output_module_entry;
#define phpext_output_ptr &output_module_entry
diff --git a/main/SAPI.c b/main/SAPI.c
index 30d0db76b1..2da12e5b83 100644
--- a/main/SAPI.c
+++ b/main/SAPI.c
@@ -229,7 +229,15 @@ SAPI_API int sapi_add_header(char *header_line, uint header_line_len)
SLS_FETCH();
if (SG(headers_sent)) {
- sapi_module.sapi_error(E_WARNING, "Cannot add header information - headers already sent");
+ char *output_start_filename = php_get_output_start_filename();
+ int output_start_lineno = php_get_output_start_lineno();
+
+ if (output_start_filename) {
+ sapi_module.sapi_error(E_WARNING, "Cannot add header information - headers already sent by (output started at %s:%d)",
+ output_start_filename, output_start_lineno);
+ } else {
+ sapi_module.sapi_error(E_WARNING, "Cannot add header information - headers already sent");
+ }
efree(header_line);
return FAILURE;
}
diff --git a/main/main.c b/main/main.c
index 49f4d1eae3..4c1b34cec2 100644
--- a/main/main.c
+++ b/main/main.c
@@ -353,10 +353,10 @@ PHPAPI void php_error(int type, const char *format,...)
uint error_lineno;
char buffer[1024];
int size = 0;
+ CLS_FETCH();
ELS_FETCH();
PLS_FETCH();
-
switch (type) {
case E_CORE_ERROR:
case E_CORE_WARNING:
@@ -365,21 +365,20 @@ PHPAPI void php_error(int type, const char *format,...)
break;
case E_PARSE:
case E_COMPILE_ERROR:
- case E_COMPILE_WARNING: {
- CLS_FETCH();
-
- error_filename = zend_get_compiled_filename();
- error_lineno = CG(zend_lineno);
- if (!error_filename) {
- error_filename = zend_get_executed_filename(ELS_C);
- }
- }
- break;
+ case E_COMPILE_WARNING:
case E_ERROR:
case E_NOTICE:
case E_WARNING:
- error_filename = zend_get_executed_filename(ELS_C);
- error_lineno = zend_get_executed_lineno(ELS_C);
+ if (zend_is_compiling()) {
+ error_filename = zend_get_compiled_filename(CLS_C);
+ error_lineno = zend_get_compiled_lineno(CLS_C);
+ } else if (zend_is_executing()) {
+ error_filename = zend_get_executed_filename(ELS_C);
+ error_lineno = zend_get_executed_lineno(ELS_C);
+ } else {
+ error_filename = NULL;
+ error_lineno = 0;
+ }
break;
default:
error_filename = NULL;
diff --git a/main/output.c b/main/output.c
index f115a7bab6..b7fa6ebca1 100644
--- a/main/output.c
+++ b/main/output.c
@@ -46,6 +46,8 @@ typedef struct {
uint ob_block_size;
uint ob_text_length;
unsigned char implicit_flush;
+ char *output_start_filename;
+ int output_start_lineno;
} php_output_globals;
#ifdef ZTS
@@ -79,6 +81,8 @@ static void php_output_init_globals(OLS_D)
OG(ob_block_size) = 0;
OG(ob_text_length) = 0;
OG(implicit_flush) = 0;
+ OG(output_start_filename) = NULL;
+ OG(output_start_lineno) = 0;
}
@@ -342,6 +346,18 @@ static int php_ub_body_write(const char *str, uint str_length)
zend_bailout();
}
if (php_header()) {
+ if (zend_is_compiling()) {
+ CLS_FETCH();
+
+ OG(output_start_filename) = zend_get_compiled_filename(CLS_C);
+ OG(output_start_lineno) = zend_get_compiled_lineno(CLS_C);
+ } else if (zend_is_executing()) {
+ ELS_FETCH();
+
+ OG(output_start_filename) = zend_get_executed_filename(ELS_C);
+ OG(output_start_lineno) = zend_get_executed_lineno(ELS_C);
+ }
+
OG(php_body_write) = php_ub_body_write_no_header;
result = php_ub_body_write_no_header(str, str_length);
}
@@ -409,6 +425,22 @@ PHP_FUNCTION(ob_implicit_flush)
}
+PHPAPI char *php_get_output_start_filename()
+{
+ OLS_FETCH();
+
+ return OG(output_start_filename);
+}
+
+
+PHPAPI int php_get_output_start_lineno()
+{
+ OLS_FETCH();
+
+ return OG(output_start_lineno);
+}
+
+
/*
* Local variables:
diff --git a/main/php_output.h b/main/php_output.h
index 17c8424429..95c6c26ede 100644
--- a/main/php_output.h
+++ b/main/php_output.h
@@ -30,7 +30,8 @@ PHPAPI void php_end_ob_buffering(int send_buffer);
PHPAPI int php_ob_get_buffer(pval *p);
PHPAPI void php_start_implicit_flush();
PHPAPI void php_end_implicit_flush();
-
+PHPAPI char *php_get_output_start_filename();
+PHPAPI int php_get_output_start_lineno();
extern zend_module_entry output_module_entry;
#define phpext_output_ptr &output_module_entry