On Wed, 1 Sep 2004 17:24:33 -0400, Jason Garber <[EMAIL PROTECTED]> wrote: > Patch didn't come through...
Odd. I BCC'd it to my archive account and that got the attachment. Oh well, something had to go wrong. Hi All, This is my first attempt at submitting a patch so please be gentle :). The feature requested in #29416 is something I've wanted to see for a while, so I decided to have a go at adding it. I decided name ob_include described the method by which the function did it's job rather than what it was for. I have implemented it as eval_file_get_output which I feel is a better description of its purpose. The requester suggests require and _once variations but those make little sense to me so I haven't implemented those. Index: ext/standard/basic_functions.c =================================================================== RCS file: /repository/php-src/ext/standard/basic_functions.c,v retrieving revision 1.543.2.41 diff -u -r1.543.2.41 basic_functions.c --- ext/standard/basic_functions.c 30 Jul 2004 16:52:35 -0000 1.543.2.41 +++ ext/standard/basic_functions.c 1 Sep 2004 19:31:36 -0000 @@ -792,6 +792,7 @@ PHP_FE(ob_get_contents, NULL) PHP_FE(ob_implicit_flush, NULL) PHP_FE(ob_list_handlers, NULL) + PHP_FE(eval_file_get_output, NULL) /* functions from array.c */ PHP_FE(ksort, first_arg_force_ref) Index: main/output.c =================================================================== RCS file: /repository/php-src/main/output.c,v retrieving revision 1.142.2.15 diff -u -r1.142.2.15 output.c --- main/output.c 8 Aug 2003 23:44:04 -0000 1.142.2.15 +++ main/output.c 1 Sep 2004 19:31:36 -0000 @@ -927,6 +927,59 @@ } /* }}} */ +/* {{{ proto bool eval_file_get_output(STRING filename) + Execute a file and return the output. */ +PHP_FUNCTION(eval_file_get_output) +{ + zval *retval=NULL; + zval *inc_filename=NULL; + int argc = ZEND_NUM_ARGS(); + + if (argc != 1) { + ZEND_WRONG_PARAM_COUNT(); + } + + if (zend_parse_parameters(argc TSRMLS_CC, "z", &inc_filename) == FAILURE) { + RETURN_FALSE; + } + + /* create a buffer */ + if (php_start_ob_buffer(NULL, 0, 1 TSRMLS_CC)==FAILURE) { + RETURN_FALSE; + } + + /* compile the file */ + zend_op_array * new_op_array = compile_filename(ZEND_INCLUDE, inc_filename); + + if (new_op_array) { + /* execute the compiled file */ + zend_execute(new_op_array); + + efree(new_op_array); + + /* get the output */ + if (php_ob_get_buffer(return_value TSRMLS_CC) == FAILURE) + RETURN_FALSE; + + /* error checks */ + if (!OG(ob_nesting_level)) { + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer. No buffer to delete."); + RETURN_FALSE; + } + if (OG(ob_nesting_level) && !OG(active_ob_buffer).status && !OG(active_ob_buffer).erase) { + php_error_docref("ref.outcontrol" TSRMLS_CC, E_NOTICE, "failed to delete buffer %s.", OG(active_ob_buffer).handler_name); + RETURN_FALSE; + } + /* delete buffer */ + php_end_ob_buffer(0, 0 TSRMLS_CC); + } + else + { + RETURN_FALSE; + } +} +/* }}} */ + /* {{{ int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result) */ static int php_ob_buffer_status(php_ob_buffer *ob_buffer, zval *result) { Index: main/php_output.h =================================================================== RCS file: /repository/php-src/main/php_output.h,v retrieving revision 1.47.2.1 diff -u -r1.47.2.1 php_output.h --- main/php_output.h 31 Dec 2002 16:26:19 -0000 1.47.2.1 +++ main/php_output.h 1 Sep 2004 19:31:36 -0000 @@ -58,6 +58,7 @@ PHP_FUNCTION(ob_get_status); PHP_FUNCTION(ob_implicit_flush); PHP_FUNCTION(ob_list_handlers); +PHP_FUNCTION(eval_file_get_output); typedef struct _php_ob_buffer { char *buffer; -- Stuart -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php