Add get_func_args()

This commit is contained in:
Zeev Suraski 1999-09-21 07:31:24 +00:00
parent 9f1d0dec47
commit a30f028a12

View File

@ -26,8 +26,9 @@
#include "zend_constants.h"
static ZEND_FUNCTION(zend_version);
static ZEND_FUNCTION(uf_num_args);
static ZEND_FUNCTION(uf_get_arg);
static ZEND_FUNCTION(func_num_args);
static ZEND_FUNCTION(func_get_arg);
static ZEND_FUNCTION(func_get_args);
static ZEND_FUNCTION(strlen);
static ZEND_FUNCTION(strcmp);
static ZEND_FUNCTION(strcasecmp);
@ -42,8 +43,9 @@ static ZEND_FUNCTION(leak);
static zend_function_entry builtin_functions[] = {
ZEND_FE(zend_version, NULL)
ZEND_FE(uf_num_args, NULL)
ZEND_FE(uf_get_arg, NULL)
ZEND_FE(func_num_args, NULL)
ZEND_FE(func_get_arg, NULL)
ZEND_FE(func_get_args, NULL)
ZEND_FE(strlen, NULL)
ZEND_FE(strcmp, NULL)
ZEND_FE(strcasecmp, NULL)
@ -71,26 +73,26 @@ ZEND_FUNCTION(zend_version)
}
ZEND_FUNCTION(uf_num_args)
ZEND_FUNCTION(func_num_args)
{
void **p;
int arg_count;
ELS_FETCH();
p = EG(argument_stack).top_element-1;
arg_count = (ulong) *p; /* this is the amount of arguments passed to uf_num_args(); */
arg_count = (ulong) *p; /* this is the amount of arguments passed to func_num_args(); */
p = EG(argument_stack).top_element-1-arg_count-1;
if (p>=EG(argument_stack).elements) {
RETURN_LONG((ulong) *p);
} else {
zend_error(E_WARNING, "uf_num_args(): Called from the global scope - no function context");
zend_error(E_WARNING, "func_num_args(): Called from the global scope - no function context");
RETURN_LONG(-1);
}
}
ZEND_FUNCTION(uf_get_arg)
ZEND_FUNCTION(func_get_arg)
{
void **p;
int arg_count;
@ -106,16 +108,17 @@ ZEND_FUNCTION(uf_get_arg)
requested_offset = (*z_requested_offset)->value.lval;
p = EG(argument_stack).top_element-1;
arg_count = (ulong) *p; /* this is the amount of arguments passed to uf_num_args(); */
arg_count = (ulong) *p; /* this is the amount of arguments passed to func_num_args(); */
p = EG(argument_stack).top_element-1-arg_count-1;
if (p<EG(argument_stack).elements) {
zend_error(E_WARNING, "func_get_arg(): Called from the global scope - no function context");
RETURN_FALSE;
}
arg_count = (ulong) *p;
if (requested_offset>arg_count) {
zend_error(E_WARNING, "uf_get_arg(): Only %d arguments passed to function (argument %d requested)", arg_count, requested_offset);
zend_error(E_WARNING, "func_get_arg(): Only %d arguments passed to function (argument %d requested)", arg_count, requested_offset);
RETURN_FALSE;
}
@ -124,6 +127,38 @@ ZEND_FUNCTION(uf_get_arg)
zval_copy_ctor(return_value);
}
ZEND_FUNCTION(func_get_args)
{
void **p;
int arg_count;
int i;
ELS_FETCH();
p = EG(argument_stack).top_element-1;
arg_count = (ulong) *p; /* this is the amount of arguments passed to func_num_args(); */
p = EG(argument_stack).top_element-1-arg_count-1;
if (p<EG(argument_stack).elements) {
zend_error(E_WARNING, "func_get_args(): Called from the global scope - no function context");
RETURN_FALSE;
}
arg_count = (ulong) *p;
array_init(return_value);
for (i=0; i<arg_count; i++) {
zval *element;
element = (zval *) emalloc(sizeof(zval));
*element = **((zval **) (p-(arg_count-i)));
zval_copy_ctor(element);
INIT_PZVAL(element);
zend_hash_next_index_insert(return_value->value.ht, &element, sizeof(zval *), NULL);
}
}
/* {{{ proto int strlen(string str)
Get string length */
ZEND_FUNCTION(strlen)