From: Sean Bright Date: Mon, 21 May 2001 13:36:42 +0000 (+0000) Subject: Added get_defined_constants() function. Returns an associative array of X-Git-Tag: PRE_GRANULAR_GARBAGE_FIX~309 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0b716d18b1e05bd0281a61cbd47ff837e6e3abd6;p=php 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. --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index d541627e0e..659187f3a5 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -382,6 +382,7 @@ function_entry basic_functions[] = { PHP_FE(get_loaded_extensions, NULL) PHP_FE(extension_loaded, NULL) PHP_FE(get_extension_funcs, NULL) + PHP_FE(get_defined_constants, 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; } +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) Return an array containing names of 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) Returns true if the named extension is loaded */ diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h index 8a3c1e3de6..52c23a25e0 100644 --- a/ext/standard/basic_functions.h +++ b/ext/standard/basic_functions.h @@ -111,6 +111,7 @@ PHP_NAMED_FUNCTION(php_if_crc32); PHP_FUNCTION(get_loaded_extensions); PHP_FUNCTION(extension_loaded); PHP_FUNCTION(get_extension_funcs); +PHP_FUNCTION(get_defined_constants); PHP_FUNCTION(register_tick_function); PHP_FUNCTION(unregister_tick_function);