]> granicus.if.org Git - php/commitdiff
Added get_defined_constants() function. Returns an associative array of
authorSean Bright <elixer@php.net>
Mon, 21 May 2001 13:36:42 +0000 (13:36 +0000)
committerSean Bright <elixer@php.net>
Mon, 21 May 2001 13:36:42 +0000 (13:36 +0000)
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.

ext/standard/basic_functions.c
ext/standard/basic_functions.h

index d541627e0eb3051738d6968350e0987e06a9ceea..659187f3a50230211558dc7f532cfc50db1d6930 100644 (file)
@@ -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 */
index 8a3c1e3de6ccd09a7cd184ec923799ade579b178..52c23a25e0b96d43a4a604320c8bb043decb7cd0 100644 (file)
@@ -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);