]> granicus.if.org Git - php/commitdiff
Use the new state functions
authorZeev Suraski <zeev@php.net>
Fri, 4 Feb 2000 14:54:30 +0000 (14:54 +0000)
committerZeev Suraski <zeev@php.net>
Fri, 4 Feb 2000 14:54:30 +0000 (14:54 +0000)
@- 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)

ext/standard/output.c
ext/standard/php_output.h
main/SAPI.c
main/main.c
main/output.c
main/php_output.h

index f115a7bab6c1fb46f7c18f115ddcd2e69a87d7f6..b7fa6ebca1772bd9c7c1737ce6d20845d8eef37e 100644 (file)
@@ -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:
index 17c8424429730aaecbf2a2efe3ddf0b5492d305a..95c6c26ede83f9a9acecd76faf31d19f8d488a74 100644 (file)
@@ -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
index 30d0db76b109e9e9b987f308cb5cb560b14c57f0..2da12e5b836c2375facd74df32c7ea573bcfecc4 100644 (file)
@@ -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;
        }
index 49f4d1eae391de97b5d8f8c6749b2c3a8ee5ccb5..4c1b34cec227d50c88b5d087bb9243e6d5e555ba 100644 (file)
@@ -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;
index f115a7bab6c1fb46f7c18f115ddcd2e69a87d7f6..b7fa6ebca1772bd9c7c1737ce6d20845d8eef37e 100644 (file)
@@ -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:
index 17c8424429730aaecbf2a2efe3ddf0b5492d305a..95c6c26ede83f9a9acecd76faf31d19f8d488a74 100644 (file)
@@ -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