Added get_defined_constants() function. Returns an associative array of

constants mapped to their values.
@- Added get_defined_constants() function to return an associative array of
@  constants mapped to their values. (Sean)
# If anyone sees a problem let me know.
This commit is contained in:
Sean Bright 2001-05-21 13:36:42 +00:00
parent 97ed89521e
commit 0b716d18b1
2 changed files with 22 additions and 0 deletions

View File

@ -382,6 +382,7 @@ function_entry basic_functions[] = {
PHP_FE(get_loaded_extensions, NULL) PHP_FE(get_loaded_extensions, NULL)
PHP_FE(extension_loaded, NULL) PHP_FE(extension_loaded, NULL)
PHP_FE(get_extension_funcs, NULL) PHP_FE(get_extension_funcs, NULL)
PHP_FE(get_defined_constants, NULL)
PHP_FE(parse_ini_file, NULL) PHP_FE(parse_ini_file, NULL)
@ -2365,6 +2366,13 @@ static int php_add_extension_info(zend_module_entry *module, void *arg)
return 0; return 0;
} }
static int php_add_constant_info(zend_constant *constant, void *arg)
{
zval *name_array = (zval *)arg;
add_assoc_zval(name_array, constant->name, &(constant->value));
return 0;
}
/* {{{ proto array get_loaded_extensions(void) /* {{{ proto array get_loaded_extensions(void)
Return an array containing names of loaded extensions */ Return an array containing names of loaded extensions */
PHP_FUNCTION(get_loaded_extensions) PHP_FUNCTION(get_loaded_extensions)
@ -2378,6 +2386,19 @@ PHP_FUNCTION(get_loaded_extensions)
} }
/* }}} */ /* }}} */
/* {{{ proto array get_defined_constants(void)
Return an array containing the names and values of all defined constants */
PHP_FUNCTION(get_defined_constants)
{
ELS_FETCH();
if (ZEND_NUM_ARGS() != 0) {
WRONG_PARAM_COUNT;
}
array_init(return_value);
zend_hash_apply_with_argument(EG(zend_constants), (int (*)(void *, void*)) php_add_constant_info, return_value);
}
/* {{{ proto bool extension_loaded(string extension_name) /* {{{ proto bool extension_loaded(string extension_name)
Returns true if the named extension is loaded */ Returns true if the named extension is loaded */

View File

@ -111,6 +111,7 @@ PHP_NAMED_FUNCTION(php_if_crc32);
PHP_FUNCTION(get_loaded_extensions); PHP_FUNCTION(get_loaded_extensions);
PHP_FUNCTION(extension_loaded); PHP_FUNCTION(extension_loaded);
PHP_FUNCTION(get_extension_funcs); PHP_FUNCTION(get_extension_funcs);
PHP_FUNCTION(get_defined_constants);
PHP_FUNCTION(register_tick_function); PHP_FUNCTION(register_tick_function);
PHP_FUNCTION(unregister_tick_function); PHP_FUNCTION(unregister_tick_function);