cvs: php4 /ext/standard basic_functions.c basic_functions.h
| From: | Sean Bright | Date: | Mon, 21 May 2001 13:36:43 +0000 |
| Subject: | cvs: php4 /ext/standard basic_functions.c basic_functions.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-5889@lists.php.net to get a copy of this message | ||
elixer Mon May 21 06:36:43 2001 EDT
Modified files:
/php4/ext/standard basic_functions.c basic_functions.h
Log:
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.
Index: php4/ext/standard/basic_functions.c
diff -u php4/ext/standard/basic_functions.c:1.342 php4/ext/standard/basic_functions.c:1.343
--- php4/ext/standard/basic_functions.c:1.342 Sat May 19 17:23:49 2001
+++ php4/ext/standard/basic_functions.c Mon May 21 06:36:42 2001
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.c,v 1.342 2001/05/20 00:23:49 derick Exp $ */
+/* $Id: basic_functions.c,v 1.343 2001/05/21 13:36:42 elixer Exp $ */
#include "php.h"
#include "php_main.h"
@@ -382,6 +382,7 @@
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 @@
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 @@
}
/* }}} */
+/* {{{ 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: php4/ext/standard/basic_functions.h
diff -u php4/ext/standard/basic_functions.h:1.77 php4/ext/standard/basic_functions.h:1.78
--- php4/ext/standard/basic_functions.h:1.77 Fri May 18 16:38:46 2001
+++ php4/ext/standard/basic_functions.h Mon May 21 06:36:42 2001
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: basic_functions.h,v 1.77 2001/05/18 23:38:46 sas Exp $ */
+/* $Id: basic_functions.h,v 1.78 2001/05/21 13:36:42 elixer Exp $ */
#ifndef BASIC_FUNCTIONS_H
#define BASIC_FUNCTIONS_H
@@ -111,6 +111,7 @@
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);