[patch] func_get_arg & friends usable as function arguments
| From: | Flavien LEBARBE | Date: | Wed, 05 Apr 2000 14:25:51 +0000 |
| Subject: | [patch] func_get_arg & friends usable as function arguments | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-17639@lists.php.net to get a copy of this message | ||
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@ocare.com 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;