cvs: php4 /ext/standard basic_functions.c basic_functions.h

From: Date: Fri, 08 Dec 2000 14:37:49 +0000
Subject: cvs: php4 /ext/standard basic_functions.c basic_functions.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-3034@lists.php.net to get a copy of this message
sterling Fri Dec 8 06:37:49 2000 EDT Modified files: /php4/ext/standard basic_functions.c basic_functions.h Log: @ Added the call_user_method_array function which allows you to call a method with an @ arbitrary number of parameters. (Sterling) Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.284 php4/ext/standard/basic_functions.c:1.285 --- php4/ext/standard/basic_functions.c:1.284 Thu Dec 7 07:33:30 2000 +++ php4/ext/standard/basic_functions.c Fri Dec 8 06:37:49 2000 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.284 2000/12/07 15:33:30 sas Exp $ */ +/* $Id: basic_functions.c,v 1.285 2000/12/08 14:37:49 sterling Exp $ */ #include "php.h" #include "php_main.h" @@ -327,6 +327,7 @@ PHP_FE(call_user_func, NULL) PHP_FE(call_user_func_array, NULL) PHP_FE(call_user_method, NULL) + PHP_FE(call_user_method_array, NULL) PHP_FE(var_dump, NULL) PHP_FE(serialize, first_arg_allow_ref) @@ -1624,6 +1625,48 @@ php_error(E_WARNING,"Unable to call %s() - function does not exist", Z_STRVAL_PP(params[0])); } efree(params); +} +/* }}} */ + +/* {{{ proto mixed call_user_method_array(object obj, string methodname, array params) + Call a user method using a parameter array */ +PHP_FUNCTION(call_user_method_array) +{ + zval **method_name, + **obj, + **params, + ***method_args = NULL, + *retval_ptr; + HashTable *params_ar; + int num_elems, + element = 0; + CLS_FETCH(); + + if (ZEND_NUM_ARGS() != 3 || + zend_get_parameters_ex(3, &method_name, &obj, &params) == FAILURE) { + WRONG_PARAM_COUNT; + } + convert_to_string_ex(method_name); + convert_to_object_ex(obj); + convert_to_array_ex(params); + + params_ar = HASH_OF(*params); + num_elems = zend_hash_num_elements(params_ar); + method_args = (zval ***)emalloc(sizeof(zval **) * num_elems); + + for (zend_hash_internal_pointer_reset(params_ar); + zend_hash_get_current_data(params_ar, (void **)&(method_args[element])) == SUCCESS; + zend_hash_move_forward(params_ar)) + element++; + + if (call_user_function_ex(CG(function_table), *obj, *method_name, &retval_ptr, num_elems, method_args, 1, NULL) == SUCCESS + && retval_ptr) { + COPY_PZVAL_TO_ZVAL(*return_value, retval_ptr); + } else { + php_error(E_WARNING, "Unable to call %s() - function does not exist", Z_STRVAL_PP(method_name)); + } + + efree(method_args); } /* }}} */ Index: php4/ext/standard/basic_functions.h diff -u php4/ext/standard/basic_functions.h:1.69 php4/ext/standard/basic_functions.h:1.70 --- php4/ext/standard/basic_functions.h:1.69 Wed Nov 29 07:37:38 2000 +++ php4/ext/standard/basic_functions.h Fri Dec 8 06:37:49 2000 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.h,v 1.69 2000/11/29 15:37:38 sterling Exp $ */ +/* $Id: basic_functions.h,v 1.70 2000/12/08 14:37:49 sterling Exp $ */ #ifndef BASIC_FUNCTIONS_H #define BASIC_FUNCTIONS_H @@ -82,6 +82,7 @@ PHP_FUNCTION(call_user_func); PHP_FUNCTION(call_user_func_array); PHP_FUNCTION(call_user_method); +PHP_FUNCTION(call_user_method_array); PHP_FUNCTION(register_shutdown_function); PHP_FUNCTION(highlight_file);

« previous php.cvs (#3034) next »