diff options
| author | Sterling Hughes <sterling@php.net> | 2000-11-24 21:05:25 +0000 | 
|---|---|---|
| committer | Sterling Hughes <sterling@php.net> | 2000-11-24 21:05:25 +0000 | 
| commit | 0d1bcd480cf7c7d8f7d02b332528485f02586ee0 (patch) | |
| tree | 663ad31916eb92418afd4baae821a6d780e7868f | |
| parent | 917cfd14e9dab1f24513053621df67455b2157a6 (diff) | |
| download | php-git-0d1bcd480cf7c7d8f7d02b332528485f02586ee0.tar.gz | |
@ Added the call_user_func_array() function which gives you the ability to
@ call a user function by passing an array of parameters as the second
@ argument.
@ Added the constant() function which returns the value of a constant given
@ the constant's name.
| -rw-r--r-- | ext/standard/basic_functions.c | 61 | ||||
| -rw-r--r-- | ext/standard/basic_functions.h | 2 | 
2 files changed, 63 insertions, 0 deletions
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index f62d495510..4dc2c8115f 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -89,6 +89,7 @@ int test_class_set_property(zend_property_reference *property_reference, pval *v  void test_class_call_function(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference);  function_entry basic_functions[] = { +    PHP_FE(constant,                                NULL)  	PHP_FE(intval,									NULL)  	PHP_FE(doubleval,								NULL)  	PHP_FE(strval,									NULL) @@ -323,6 +324,7 @@ function_entry basic_functions[] = {  	PHP_FE(error_log,								NULL)  	PHP_FE(call_user_func,							NULL) +	PHP_FE(call_user_func_array,                    NULL)  	PHP_FE(call_user_method,						NULL)  	PHP_FE(var_dump,								NULL) @@ -862,6 +864,26 @@ PHP_MINFO_FUNCTION(basic)  	PHP_MINFO(assert)(ZEND_MODULE_INFO_FUNC_ARGS_PASSTHRU);  } +/* {{{ proto mixed constant(string const_name) +   Given the name of a constant this function will return the constants associated value */ +PHP_FUNCTION(constant) +{ +    zval **const_name; +     +    if (ZEND_NUM_ARGS() != 1 || +        zend_get_parameters_ex(1, &const_name) == FAILURE) { +        WRONG_PARAM_COUNT; +    } +    convert_to_string_ex(const_name); +     +    if (!zend_get_constant(Z_STRVAL_PP(const_name), Z_STRLEN_PP(const_name), return_value)) { +        php_error(E_WARNING, "Couldn't find constant %s", Z_STRVAL_PP(const_name)); +        RETURN_NULL(); +    } +} +/* }}} */ + +  /* {{{ proto int ip2long(string ip_address)     Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address */  PHP_FUNCTION(ip2long) @@ -1518,6 +1540,45 @@ PHP_FUNCTION(call_user_func)  }  /* }}} */ +/* {{{ proto mixed call_user_func_array(string function_name, array parameters) +   Call a user function which is the first parameter with the arguments contained in array */ +PHP_FUNCTION(call_user_func_array) +{ +    zval **func_name, +         **params, +         ***func_args = NULL, +         *retval_ptr; +    HashTable *params_ar; +    int num_elems, +        element = 0; +     +    if (ZEND_NUM_ARGS() != 2 || +        zend_get_parameters_ex(2, &func_name, ¶ms) == FAILURE) { +        WRONG_PARAM_COUNT; +    } +    convert_to_string_ex(func_name); +     +    params_ar = HASH_OF(*params); +    num_elems = zend_hash_num_elements(params_ar); +     +    func_args = (zval ***)emalloc(sizeof(zval **) * num_elems); +     +    for (zend_hash_internal_pointer_reset(params_ar); +         zend_hash_get_current_data(params_ar, (void **)&(func_args[element])) == SUCCESS; +         zend_hash_move_forward(params_ar)) +         element++; +     +    if (call_user_function_ex(CG(function_table), NULL, *func_name, &retval_ptr, num_elems, func_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(func_name)); +    } +     +    efree(func_args); +} +/* }}} */ +  /* {{{ proto mixed call_user_method(string method_name, object object [, mixed parameter] [, mixed ...])     Call a user method, on a specific object where the first argument is the method name, the second argument is the object and the subsequent arguments are the parameters */  PHP_FUNCTION(call_user_method) diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 9c3ed32ae5..b164ec1ec1 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -41,6 +41,7 @@ PHP_RSHUTDOWN_FUNCTION(basic);  PHP_MINFO_FUNCTION(basic);  PHP_GINIT_FUNCTION(basic); +PHP_FUNCTION(constant);  PHP_FUNCTION(intval);  PHP_FUNCTION(doubleval);  PHP_FUNCTION(strval); @@ -78,6 +79,7 @@ PHP_FUNCTION(is_object);  PHP_FUNCTION(error_log);  PHP_FUNCTION(call_user_func); +PHP_FUNCTION(call_user_func_array);  PHP_FUNCTION(call_user_method);  PHP_FUNCTION(register_shutdown_function);  | 
