Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:12535 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55222 invoked by uid 1010); 1 Sep 2004 21:49:08 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 44180 invoked from network); 1 Sep 2004 21:47:44 -0000 Received: from unknown (HELO mproxy.gmail.com) (64.233.170.205) by pb1.pair.com with SMTP; 1 Sep 2004 21:47:44 -0000 Received: by mproxy.gmail.com with SMTP id 79so288999rnk for ; Wed, 01 Sep 2004 14:47:43 -0700 (PDT) Received: by 10.38.70.76 with SMTP id s76mr670803rna; Wed, 01 Sep 2004 14:47:43 -0700 (PDT) Received: by 10.38.89.34 with HTTP; Wed, 1 Sep 2004 14:47:43 -0700 (PDT) Message-ID: <8dd3173f04090114471aa25f2a@mail.gmail.com> Date: Wed, 1 Sep 2004 22:47:43 +0100 Reply-To: Stuart Dallas To: internals@lists.php.net Cc: Jason Garber In-Reply-To: <836225669.20040901172433@ionzoft.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: <8dd3173f04090112506e5891@mail.gmail.com> <836225669.20040901172433@ionzoft.com> Subject: Re: [PHP-DEV] [PATCH] #29416 - ob_include From: stuart.dallas@gmail.com (Stuart Dallas) On Wed, 1 Sep 2004 17:24:33 -0400, Jason Garber 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