Re: [PHP-DEV] [patch] func_get_arg & friends usable as function arguments From: Andi Gutmans (andi <email protected>)
Date: 04/05/00

We will take a look at the patch and get back to you.
We thought of doing it but didn't want to introduce anything new so close
to the release of PHP 4. We thought that for the time being we should just
fix and make them work as advertized.
Anyway, we'll get back to you and if we forget, bug us :)

Andi

At 04:25 PM 4/5/00 +0200, Flavien LEBARBE wrote:
>I'm back again with func_get_args and func_num_args...
>But with a patch this time ! :-)
>
>Take a look at this dummy-example :
>
> <?php
> function echovalues($val1, $val2) {
> echo "This is val 1 :".$val1."\n";
> echo "This is val 2 :".$val2."\n";
> }
>
> function printme(){
> echo implode("\n",func_get_args())."\n";
> echovalues(0,func_num_args());
> }
>
> printme(0,"one",2,"three");
> ?>
>
>With current cvs, you get fatal errors :
> func_get_args(): Can't be used as a function parameter
> func_num_args(): Can't be used as a function parameter
>
>With the following patch applied, you get :
> 0
> one
> 2
> three
> This is val 1 :0
> This is val 2 :4
>which is the result one would expect.
>
>
>This patch just looks down the argument_stack for the NULL
>that was put on the stack on the top of param_count.
>( see zend_execute_API.c on line 387 :
> zend_ptr_stack_n_push(&EG(argument_stack), 2, (void *) (long)
> param_count, NULL);
>)
>
>Andi, Zeev, is this patch ok ? Did I miss something ?
>Is there a specific reason why you didn't look for
>the NULL down the stack and prefered to return an error ?
>
>Flavien Lebarbe.
>--
>Flavien LEBARBE OPEN CARE Support for Freedom
>mailto:flebarbe <email protected> http://www.ocare.com
>Tel:+33 141430890 Fax:+33 141430891
>
>--------------------------------------------------------
>--- zend_builtin_functions.c.orig Wed Apr 5 12:21:39 2000
>+++ zend_builtin_functions.c Wed Apr 5 15:19:59 2000
>@@ -110,8 +110,8 @@
> p = EG(argument_stack).top_element-1-1;
> arg_count = (ulong) *p; /* this is the amount of
> arguments passed to func_num_args(); */
> p -= 1+arg_count;
>- if (*p) {
>- zend_error(E_ERROR, "func_num_args(): Can't be used as a
>function parameter");
>+ while (*p) { /* Find last function call on the
>stack */
>+ p--;
> }
> --p;
> if (p>=EG(argument_stack).elements) {
>@@ -140,8 +140,8 @@
> p = EG(argument_stack).top_element-1-1;
> arg_count = (ulong) *p; /* this is the amount of
> arguments passed to func_get_arg(); */
> p -= 1+arg_count;
>- if (*p) {
>- zend_error(E_ERROR, "func_get_arg(): Can't be used as a
>function parameter");
>+ while (*p) { /* Find last function call on the
>stack */
>+ p--;
> }
> --p;
> if (p<EG(argument_stack).elements) {
>@@ -170,8 +170,8 @@
> p = EG(argument_stack).top_element-1-1;
> arg_count = (ulong) *p; /* this is the amount of
> arguments passed to func_get_args(); */
> p -= 1+arg_count;
>- if (*p) {
>- zend_error(E_ERROR, "func_get_args(): Can't be used as a
>function parameter");
>+ while (*p) { /* Find last function call on the
>stack */
>+ p--;
> }
> --p;
>
>--
>PHP Development Mailing List <http://www.php.net/>
>To unsubscribe, e-mail: php-dev-unsubscribe <email protected>
>For additional commands, e-mail: php-dev-help <email protected>
>To contact the list administrators, e-mail: php-list-admin <email protected>

---
Andi Gutmans <andi <email protected>>
http://www.zend.com/

-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>